@@ -2383,23 +2383,11 @@ bool Ast::getReferencedAttributes(AstNode const* node, Variable const* variable,
2383
2383
return state.isSafeForOptimization ;
2384
2384
}
2385
2385
2386
- // / @brief recursively clone a node
2387
- AstNode* Ast::clone (AstNode const * node) {
2386
+ // / @brief copies node payload from node into copy. this is *not* copying
2387
+ // / the subnodes
2388
+ void Ast::copyPayload (AstNode const * node, AstNode* copy) const {
2388
2389
AstNodeType const type = node->type ;
2389
- if (type == NODE_TYPE_NOP) {
2390
- // nop node is a singleton
2391
- return const_cast <AstNode*>(node);
2392
- }
2393
2390
2394
- AstNode* copy = createNode (type);
2395
- TRI_ASSERT (copy != nullptr );
2396
-
2397
- // copy flags
2398
- copy->flags = node->flags ;
2399
- TEMPORARILY_UNLOCK_NODE (copy); // if locked, unlock to copy properly
2400
-
2401
- // special handling for certain node types
2402
- // copy payload...
2403
2391
if (type == NODE_TYPE_COLLECTION || type == NODE_TYPE_VIEW || type == NODE_TYPE_PARAMETER ||
2404
2392
type == NODE_TYPE_PARAMETER_DATASOURCE || type == NODE_TYPE_ATTRIBUTE_ACCESS ||
2405
2393
type == NODE_TYPE_OBJECT_ELEMENT || type == NODE_TYPE_FCALL_USER) {
@@ -2448,7 +2436,27 @@ AstNode* Ast::clone(AstNode const* node) {
2448
2436
break ;
2449
2437
}
2450
2438
}
2439
+ }
2440
+
2441
+ // / @brief recursively clone a node
2442
+ AstNode* Ast::clone (AstNode const * node) {
2443
+ AstNodeType const type = node->type ;
2444
+ if (type == NODE_TYPE_NOP) {
2445
+ // nop node is a singleton
2446
+ return const_cast <AstNode*>(node);
2447
+ }
2448
+
2449
+ AstNode* copy = createNode (type);
2450
+ TRI_ASSERT (copy != nullptr );
2451
2451
2452
+ // copy flags
2453
+ copy->flags = node->flags ;
2454
+ TEMPORARILY_UNLOCK_NODE (copy); // if locked, unlock to copy properly
2455
+
2456
+ // special handling for certain node types
2457
+ // copy payload...
2458
+ copyPayload (node, copy);
2459
+
2452
2460
// recursively clone subnodes
2453
2461
size_t const n = node->numMembers ();
2454
2462
copy->members .reserve (n);
@@ -2474,59 +2482,13 @@ AstNode* Ast::shallowCopyForModify(AstNode const* node) {
2474
2482
2475
2483
// special handling for certain node types
2476
2484
// copy payload...
2477
- if (type == NODE_TYPE_COLLECTION || type == NODE_TYPE_VIEW || type == NODE_TYPE_PARAMETER ||
2478
- type == NODE_TYPE_PARAMETER_DATASOURCE || type == NODE_TYPE_ATTRIBUTE_ACCESS ||
2479
- type == NODE_TYPE_OBJECT_ELEMENT || type == NODE_TYPE_FCALL_USER) {
2480
- copy->setStringValue (node->getStringValue (), node->getStringLength ());
2481
- } else if (type == NODE_TYPE_VARIABLE || type == NODE_TYPE_REFERENCE || type == NODE_TYPE_FCALL) {
2482
- copy->setData (node->getData ());
2483
- } else if (type == NODE_TYPE_UPSERT || type == NODE_TYPE_EXPANSION) {
2484
- copy->setIntValue (node->getIntValue (true ));
2485
- } else if (type == NODE_TYPE_QUANTIFIER) {
2486
- copy->setIntValue (node->getIntValue (true ));
2487
- } else if (type == NODE_TYPE_OPERATOR_BINARY_IN || type == NODE_TYPE_OPERATOR_BINARY_NIN ||
2488
- type == NODE_TYPE_OPERATOR_BINARY_ARRAY_IN ||
2489
- type == NODE_TYPE_OPERATOR_BINARY_ARRAY_NIN) {
2490
- // copy sortedness information
2491
- copy->setBoolValue (node->getBoolValue ());
2492
- } else if (type == NODE_TYPE_ARRAY) {
2493
- if (node->isSorted ()) {
2494
- copy->setFlag (DETERMINED_SORTED, VALUE_SORTED);
2495
- } else {
2496
- copy->setFlag (DETERMINED_SORTED);
2497
- }
2498
- } else if (type == NODE_TYPE_VALUE) {
2499
- switch (node->value .type ) {
2500
- case VALUE_TYPE_NULL:
2501
- copy->value .type = VALUE_TYPE_NULL;
2502
- break ;
2503
- case VALUE_TYPE_BOOL:
2504
- copy->value .type = VALUE_TYPE_BOOL;
2505
- copy->setBoolValue (node->getBoolValue ());
2506
- break ;
2507
- case VALUE_TYPE_INT:
2508
- copy->value .type = VALUE_TYPE_INT;
2509
- copy->setIntValue (node->getIntValue ());
2510
- break ;
2511
- case VALUE_TYPE_DOUBLE:
2512
- copy->value .type = VALUE_TYPE_DOUBLE;
2513
- copy->setDoubleValue (node->getDoubleValue ());
2514
- break ;
2515
- case VALUE_TYPE_STRING:
2516
- copy->value .type = VALUE_TYPE_STRING;
2517
- copy->setStringValue (node->getStringValue (), node->getStringLength ());
2518
- break ;
2519
- }
2520
- }
2521
-
2522
- // recursively clone subnodes
2485
+ copyPayload (node, copy);
2486
+
2487
+ // recursively add subnodes
2523
2488
size_t const n = node->numMembers ();
2524
- if (n > 0 ) {
2525
- copy->members .reserve (n);
2526
-
2527
- for (size_t i = 0 ; i < n; ++i) {
2528
- copy->addMember (node->getMemberUnchecked (i));
2529
- }
2489
+ copy->members .reserve (n);
2490
+ for (size_t i = 0 ; i < n; ++i) {
2491
+ copy->addMember (node->getMemberUnchecked (i));
2530
2492
}
2531
2493
2532
2494
return copy;
0 commit comments