@@ -251,6 +251,16 @@ YGNodeRef YGNodeClone(YGNodeRef oldNode) {
251
251
return node;
252
252
}
253
253
254
+ static YGConfigRef YGConfigClone (const YGConfig& oldConfig) {
255
+ const YGConfigRef config = new YGConfig (oldConfig);
256
+ YGAssert (config != nullptr , " Could not allocate memory for config" );
257
+ if (config == nullptr ) {
258
+ abort ();
259
+ }
260
+ gConfigInstanceCount ++;
261
+ return config;
262
+ }
263
+
254
264
static YGNodeRef YGNodeDeepClone (YGNodeRef oldNode) {
255
265
YGNodeRef node = YGNodeClone (oldNode);
256
266
YGVector vec = YGVector ();
@@ -263,12 +273,12 @@ static YGNodeRef YGNodeDeepClone(YGNodeRef oldNode) {
263
273
}
264
274
node->setChildren (vec);
265
275
266
- if (oldNode->getNextChild () != nullptr ) {
267
- node->setNextChild ( YGNodeDeepClone ( oldNode->getNextChild ( )));
276
+ if (oldNode->getConfig () != nullptr ) {
277
+ node->setConfig ( YGConfigClone (*( oldNode->getConfig () )));
268
278
}
269
279
270
- if (node-> getConfig () != nullptr ) {
271
- node->setConfig ( new YGConfig (*node-> getConfig ()));
280
+ if (oldNode-> getNextChild () != nullptr ) {
281
+ node->setNextChild ( YGNodeDeepClone (oldNode-> getNextChild ()));
272
282
}
273
283
274
284
return node;
@@ -291,6 +301,17 @@ void YGNodeFree(const YGNodeRef node) {
291
301
gNodeInstanceCount --;
292
302
}
293
303
304
+ static void YGConfigFreeRecursive (const YGNodeRef root) {
305
+ if (root->getConfig () != nullptr ) {
306
+ gConfigInstanceCount --;
307
+ delete root->getConfig ();
308
+ }
309
+ // Delete configs recursively for childrens
310
+ for (uint32_t i = 0 ; i < root->getChildrenCount (); ++i) {
311
+ YGConfigFreeRecursive (root->getChild (i));
312
+ }
313
+ }
314
+
294
315
void YGNodeFreeRecursive (const YGNodeRef root) {
295
316
while (YGNodeGetChildCount (root) > 0 ) {
296
317
const YGNodeRef child = YGNodeGetChild (root, 0 );
@@ -3642,6 +3663,7 @@ void YGNodeCalculateLayout(const YGNodeRef node,
3642
3663
YGPrintOptionsStyle));
3643
3664
}
3644
3665
}
3666
+ YGConfigFreeRecursive (originalNode);
3645
3667
YGNodeFreeRecursive (originalNode);
3646
3668
}
3647
3669
}
0 commit comments