From 7e6f165b340adcf0ee4beac8e0f0aa7f2504220f Mon Sep 17 00:00:00 2001 From: Junwang Zhao Date: Thu, 17 Oct 2024 13:34:18 +0800 Subject: [PATCH] cypher::FieldData improvement (#704) 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 --- src/cypher/cypher_types.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cypher/cypher_types.h b/src/cypher/cypher_types.h index 1ad0a09f6a..928d0f0af1 100644 --- a/src/cypher/cypher_types.h +++ b/src/cypher/cypher_types.h @@ -26,7 +26,6 @@ namespace cypher { struct FieldData { typedef std::unordered_map CYPHER_FIELD_DATA_MAP; typedef std::vector CYPHER_FIELD_DATA_LIST; - // TODO(lingsu) : a default state should be added enum FieldType { SCALAR, ARRAY, MAP } type; lgraph::FieldData scalar; @@ -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); @@ -134,7 +134,7 @@ struct FieldData { map = new CYPHER_FIELD_DATA_MAP(std::move(rhs)); } - ~FieldData() { + ~FieldData() { switch (type) { case ARRAY: delete array; @@ -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; }