@@ -128,10 +128,6 @@ func ValueSemanticEqualitySetElements(ctx context.Context, req ValueSemanticEqua
128
128
// Short circuit flag
129
129
updatedElements := false
130
130
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
-
135
131
// Loop through proposed elements by delegating to the recursive semantic
136
132
// equality logic. This ensures that recursion will catch a further
137
133
// underlying element type has its semantic equality logic checked, even if
@@ -140,44 +136,33 @@ func ValueSemanticEqualitySetElements(ctx context.Context, req ValueSemanticEqua
140
136
// Ensure new value always contains all of proposed new value
141
137
newValueElements [idx ] = proposedNewValueElement
142
138
143
- if idx >= originalPriorElementsLength {
139
+ if idx >= len ( priorValueElements ) {
144
140
continue
145
141
}
146
142
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
+ }
165
151
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 )
170
153
171
- // Prior state was kept, meaning that we found a semantically equal element
172
- updatedElements = true
154
+ resp .Diagnostics .Append (elementResp .Diagnostics ... )
173
155
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
+ }
176
159
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
180
162
}
163
+
164
+ updatedElements = true
165
+ newValueElements [idx ] = elementResp .NewValue
181
166
}
182
167
183
168
// No changes required if the elements were not updated.
0 commit comments