Skip to content

Commit b37dde1

Browse files
committed
Revert "quick rewrite of semantic equality for sets"
This reverts commit 37749fd.
1 parent e0b7f9c commit b37dde1

File tree

1 file changed

+19
-34
lines changed

1 file changed

+19
-34
lines changed

internal/fwschemadata/value_semantic_equality_set.go

+19-34
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,6 @@ func ValueSemanticEqualitySetElements(ctx context.Context, req ValueSemanticEqua
128128
// Short circuit flag
129129
updatedElements := false
130130

131-
// The underlying loop will mutate priorValueElements to avoid keeping
132-
// duplicate semantically equal elements. Need the original length to avoid panicks
133-
originalPriorElementsLength := len(priorValueElements)
134-
135131
// Loop through proposed elements by delegating to the recursive semantic
136132
// equality logic. This ensures that recursion will catch a further
137133
// underlying element type has its semantic equality logic checked, even if
@@ -140,44 +136,33 @@ func ValueSemanticEqualitySetElements(ctx context.Context, req ValueSemanticEqua
140136
// Ensure new value always contains all of proposed new value
141137
newValueElements[idx] = proposedNewValueElement
142138

143-
if idx >= originalPriorElementsLength {
139+
if idx >= len(priorValueElements) {
144140
continue
145141
}
146142

147-
// Loop through all prior value elements and see if there are any semantically equal elements
148-
for pIdx, priorValue := range priorValueElements {
149-
elementReq := ValueSemanticEqualityRequest{
150-
Path: req.Path.AtSetValue(proposedNewValueElement),
151-
PriorValue: priorValue,
152-
ProposedNewValue: proposedNewValueElement,
153-
}
154-
elementResp := &ValueSemanticEqualityResponse{
155-
NewValue: elementReq.ProposedNewValue,
156-
}
157-
158-
ValueSemanticEquality(ctx, elementReq, elementResp)
159-
160-
resp.Diagnostics.Append(elementResp.Diagnostics...)
161-
162-
if resp.Diagnostics.HasError() {
163-
return
164-
}
143+
elementReq := ValueSemanticEqualityRequest{
144+
Path: req.Path.AtSetValue(proposedNewValueElement),
145+
PriorValue: priorValueElements[idx],
146+
ProposedNewValue: proposedNewValueElement,
147+
}
148+
elementResp := &ValueSemanticEqualityResponse{
149+
NewValue: elementReq.ProposedNewValue,
150+
}
165151

166-
if elementResp.NewValue.Equal(elementReq.ProposedNewValue) {
167-
// This prior value element didn't match, but there could be other elements that do
168-
continue
169-
}
152+
ValueSemanticEquality(ctx, elementReq, elementResp)
170153

171-
// Prior state was kept, meaning that we found a semantically equal element
172-
updatedElements = true
154+
resp.Diagnostics.Append(elementResp.Diagnostics...)
173155

174-
// Remove the semantically equal element from the slice of candidates
175-
priorValueElements = append(priorValueElements[:pIdx], priorValueElements[pIdx+1:]...)
156+
if resp.Diagnostics.HasError() {
157+
return
158+
}
176159

177-
// Order doesn't matter, so we can just set the prior state element to this index
178-
newValueElements[idx] = elementResp.NewValue
179-
break
160+
if elementResp.NewValue.Equal(elementReq.ProposedNewValue) {
161+
continue
180162
}
163+
164+
updatedElements = true
165+
newValueElements[idx] = elementResp.NewValue
181166
}
182167

183168
// No changes required if the elements were not updated.

0 commit comments

Comments
 (0)