MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / SI_CloneValue

Function SI_CloneValue

src/value.c:134–172  ·  view source on GitHub ↗

Make an SIValue that creates its own copies of the original's allocations, if any. * This is not a deep clone: if the inner value holds its own references, * such as the Entity pointer to the properties of a Node or Edge, those are unmodified. */

Source from the content-addressed store, hash-verified

132 * This is not a deep clone: if the inner value holds its own references,
133 * such as the Entity pointer to the properties of a Node or Edge, those are unmodified. */
134SIValue SI_CloneValue(const SIValue v) {
135 if(v.allocation == M_NONE) return v; // Stack value; no allocation necessary.
136
137 if(v.type == T_STRING) {
138 // Allocate a new copy of the input's string value.
139 return SI_DuplicateStringVal(v.stringval);
140 }
141
142 if(v.type == T_ARRAY) {
143 return SIArray_Clone(v);
144 }
145
146 if(v.type == T_PATH) {
147 return SIPath_Clone(v);
148 }
149
150 if(v.type == T_MAP) {
151 return Map_Clone(v);
152 }
153
154 // Copy the memory region for Node and Edge values. This does not modify the
155 // inner Entity pointer to the value's properties.
156 SIValue clone;
157 clone.type = v.type;
158 clone.allocation = M_SELF;
159
160 size_t size = 0;
161 if(v.type == T_NODE) {
162 size = sizeof(Node);
163 } else if(v.type == T_EDGE) {
164 size = sizeof(Edge);
165 } else {
166 ASSERT(false && "Encountered heap-allocated SIValue of unhandled type");
167 }
168
169 clone.ptrval = rm_malloc(size);
170 memcpy(clone.ptrval, v.ptrval, size);
171 return clone;
172}
173
174SIValue SI_ShallowCloneValue(const SIValue v) {
175 if(v.allocation == M_CONST || v.allocation == M_NONE) return v;

Callers 15

SI_ShallowCloneValueFunction · 0.85
SIValue_PersistFunction · 0.85
_AST_Extract_ParamsFunction · 0.85
AR_REVERSEFunction · 0.85
AGG_MINFunction · 0.85
Aggregate_CloneFunction · 0.85
AGG_MAXFunction · 0.85
AR_SUBSCRIPTFunction · 0.85
AttributeSet_AddFunction · 0.85
AttributeSet_UpdateFunction · 0.85

Calls 5

SI_DuplicateStringValFunction · 0.85
SIArray_CloneFunction · 0.85
SIPath_CloneFunction · 0.85
Map_CloneFunction · 0.85
rm_mallocFunction · 0.85

Tested by

no test coverage detected