Skip to content

Commit

Permalink
cypher::FieldData improvement (#704)
Browse files Browse the repository at this point in the history
In move constructor, rhs pointer should be set to nullptr in case
dangling pointer.

Fix an wrong indentation and remove useless comments.

Signed-off-by: Junwang Zhao <[email protected]>
  • Loading branch information
zhjwpku authored Oct 17, 2024
1 parent 113dbc0 commit 7e6f165
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/cypher/cypher_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ namespace cypher {
struct FieldData {
typedef std::unordered_map<std::string, cypher::FieldData> CYPHER_FIELD_DATA_MAP;
typedef std::vector<cypher::FieldData> CYPHER_FIELD_DATA_LIST;
// TODO(lingsu) : a default state should be added
enum FieldType { SCALAR, ARRAY, MAP } type;

lgraph::FieldData scalar;
Expand Down Expand Up @@ -116,6 +115,7 @@ struct FieldData {
map->emplace(kv);
}
}

explicit FieldData(const CYPHER_FIELD_DATA_MAP& rhs) {
type = MAP;
map = new CYPHER_FIELD_DATA_MAP(rhs);
Expand All @@ -134,7 +134,7 @@ struct FieldData {
map = new CYPHER_FIELD_DATA_MAP(std::move(rhs));
}

~FieldData() {
~FieldData() {
switch (type) {
case ARRAY:
delete array;
Expand Down Expand Up @@ -167,15 +167,16 @@ struct FieldData {
switch (type) {
case ARRAY:
array = rhs.array;
rhs.array = nullptr;
break;
case MAP:
map = rhs.map;
rhs.map = nullptr;
break;
case SCALAR:
scalar = std::move(rhs.scalar);
break;
}
// TODO(lingsu) : rhs should return to the default state
rhs.type = SCALAR;
}

Expand Down

0 comments on commit 7e6f165

Please sign in to comment.