Uploaded image for project: 'CloverDX'
  1. CloverDX
  2. CLO-17549

Allow variant reference assignment

    XMLWordPrintable

    Details

    • Type: Story
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: rel-5-6-0
    • Component/s: Engine
    • Security Level: Users (General product issues)
    • Story Points:
      8
    • QA Testing:
      UNDECIDED
    • Epic Link:
    • Sprint:
      Green Sprint 107, Green Sprint 108

      Description

      Currently, the assignment operator "=" always creates a deep copy of the right-hand side expression. This prevents unintentional modification of the original object:

      integer[] a = [4, 8, 15];
      integer[] b = a; // b == [4, 8, 15]
      clear(b); // b == []
      printErr(a); // a == [4, 8, 15]
      

      However, it has a serious performance impact for large structures, e.g. a huge tree stored in a variant. And it prevents the user from saving a subtree in a variable, so that a modification of the variable affects the original tree. This is useful when working dynamically with a tree of unknown structure:

      function setValue(variant v, string[] keys, variant value) {
        variant subTree = v;
        for (integer i = 0; i < length(keys) - 1; i++) {
          string key = keys[i];
          subTree = v[key]; // assigns a deep copy
        }
        string lastKey = keys[length(keys) - 1];
        subTree[lastKey] = value; // does not modify v, because we work with a copy
      }
      

      Introduce new function

      • function variant getReference(variant | variant_expression) - function’s effect is that the assignment operator is not the standard make-a-deep-copy-&-assign, but only assign the reference.
        variant value={1->[1,2,3],2->[“A”,”B”,”C”]};
        variant ref=getReference(value);
        ref[2]=[“X”,”Y”,”Z”]; //we changed the original map value
        variant ref2=ref; //standard assignment, copy is created & assigned
        ref2[2] = [“1”,”2”,”3”]; //no change to the original map value,change performed on a copy
        

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              slamam Martin Slama
              Reporter:
              krivanekm Milan Krivanek
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 1 day, 4 hours, 15 minutes
                  1d 4h 15m