Skip to content

Commit b990eb7

Browse files
committed
internal/core/adt: support bulk adding of conjuncts
This allows us to remove references to Vertex.Conjuncts in a few more occasions. It is assumed that in all cases we are modifying nodes pre evaluation. Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: Ia2bedb0ea4f2a73e3b31cdcbdca78e7792ac14cf Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1202661 TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Matthew Sackman <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent d21405c commit b990eb7

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

internal/core/adt/composite.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,6 +1252,12 @@ func (v *Vertex) InsertConjunct(c Conjunct) {
12521252
v.Conjuncts = append(v.Conjuncts, c)
12531253
}
12541254

1255+
// InsertConjunctsFrom is a low-level method to insert a conjuncts into a Vertex
1256+
// from another Vertex.
1257+
func (v *Vertex) InsertConjunctsFrom(w *Vertex) {
1258+
v.Conjuncts = append(v.Conjuncts, w.Conjuncts...)
1259+
}
1260+
12551261
// AddConjunct adds the given Conjuncts to v if it doesn't already exist.
12561262
func (v *Vertex) AddConjunct(c Conjunct) *Bottom {
12571263
if v.BaseValue != nil && !isCyclePlaceholder(v.BaseValue) {

pkg/list/sort.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,8 @@ func (s *valueSorter) Less(i, j int) bool {
6969
saveX := *s.x
7070
saveY := *s.y
7171

72-
for _, c := range x.V.Conjuncts {
73-
s.x.AddConjunct(c)
74-
}
75-
for _, c := range y.V.Conjuncts {
76-
s.y.AddConjunct(c)
77-
}
72+
s.x.InsertConjunctsFrom(x.V)
73+
s.y.InsertConjunctsFrom(y.V)
7874

7975
// TODO(perf): if we can determine that the comparator values for
8076
// x and y are idempotent (no arcs and a basevalue being top or
@@ -121,12 +117,8 @@ func (s *valueSorter) lessNew(i, j int) bool {
121117
s.a[i].Core(&x)
122118
s.a[j].Core(&y)
123119

124-
for _, c := range x.V.Conjuncts {
125-
xa.AddConjunct(c)
126-
}
127-
for _, c := range y.V.Conjuncts {
128-
ya.AddConjunct(c)
129-
}
120+
xa.InsertConjunctsFrom(x.V)
121+
ya.InsertConjunctsFrom(y.V)
130122

131123
// TODO(perf): if we can determine that the comparator values for
132124
// x and y are idempotent (no arcs and a basevalue being top or

tools/trim/trim.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ func (t *trimmer) addDominators(d, v *adt.Vertex, hasDisjunction bool) (doms *ad
227227
Label: v.Label,
228228
}
229229
if d != nil && hasDisjunction {
230-
doms.Conjuncts = append(doms.Conjuncts, d.Conjuncts...)
230+
doms.InsertConjunctsFrom(d)
231231
}
232232

233233
hasDoms := false

0 commit comments

Comments
 (0)