Skip to content

Commit b51914f

Browse files
committed
internal/core/adt: optimize slice
Dynamic structs are discarded after use, so if we are taking a slice, we might as well repurpose the arcs. This was discovered when fixing a bug when that was exposed by this test. b: strings.Join(["t", "e", "s", "t"][1:], "") in combination with an upcoming change that changes to use for iteration from CompleteArcs to CompleteArcsOnly. Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: I9f57c403d703678cbf4d2a79d0b96baae923f425 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1202210 TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Matthew Sackman <[email protected]>
1 parent 4eaa7b2 commit b51914f

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

internal/core/adt/expr.go

+7
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,13 @@ func (x *SliceExpr) evaluate(c *OpContext, state combinedFlags) Value {
11251125
})
11261126
return nil
11271127
}
1128+
if v.IsDynamic {
1129+
// If the list is dynamic, there is no need to recompute the
1130+
// arcs.
1131+
a.Label = label
1132+
n.Arcs = append(n.Arcs, a)
1133+
continue
1134+
}
11281135
arc := *a
11291136
arc.Parent = n
11301137
arc.Label = label

0 commit comments

Comments
 (0)