Skip to content

Commit 69b4451

Browse files
committed
Remove index from internal API/function calls
1 parent 8f90031 commit 69b4451

File tree

6 files changed

+19
-20
lines changed

6 files changed

+19
-20
lines changed

typed/compare.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ func (w *compareWalker) visitListItems(t *schema.List, lhs, rhs value.List) (err
216216
lValues := fieldpath.MakePathElementValueMap(lLen)
217217
for i := 0; i < lLen; i++ {
218218
child := lhs.At(i)
219-
pe, err := listItemToPathElement(w.allocator, w.schema, t, i, child)
219+
pe, err := listItemToPathElement(w.allocator, w.schema, t, child)
220220
if err != nil {
221221
errs = append(errs, errorf("element %v: %v", i, err.Error())...)
222222
// If we can't construct the path element, we can't
@@ -234,7 +234,7 @@ func (w *compareWalker) visitListItems(t *schema.List, lhs, rhs value.List) (err
234234
rValues := fieldpath.MakePathElementValueMap(rLen)
235235
for i := 0; i < rLen; i++ {
236236
rValue := rhs.At(i)
237-
pe, err := listItemToPathElement(w.allocator, w.schema, t, i, rValue)
237+
pe, err := listItemToPathElement(w.allocator, w.schema, t, rValue)
238238
if err != nil {
239239
errs = append(errs, errorf("element %v: %v", i, err.Error())...)
240240
// If we can't construct the path element, we can't
@@ -255,7 +255,7 @@ func (w *compareWalker) visitListItems(t *schema.List, lhs, rhs value.List) (err
255255
// Add items from left that are not in right.
256256
for i := 0; i < lLen; i++ {
257257
lValue := lhs.At(i)
258-
pe, err := listItemToPathElement(w.allocator, w.schema, t, i, lValue)
258+
pe, err := listItemToPathElement(w.allocator, w.schema, t, lValue)
259259
if err != nil {
260260
errs = append(errs, errorf("element %v: %v", i, err.Error())...)
261261
// If we can't construct the path element, we can't
@@ -282,7 +282,7 @@ func (w *compareWalker) indexListPathElements(t *schema.List, list value.List) (
282282
pes := make([]fieldpath.PathElement, 0, length)
283283
for i := 0; i < length; i++ {
284284
child := list.At(i)
285-
pe, err := listItemToPathElement(w.allocator, w.schema, t, i, child)
285+
pe, err := listItemToPathElement(w.allocator, w.schema, t, child)
286286
if err != nil {
287287
errs = append(errs, errorf("element %v: %v", i, err.Error())...)
288288
// If we can't construct the path element, we can't

typed/helpers.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ func getAssociativeKeyDefault(s *schema.Schema, list *schema.List, fieldName str
197197
return field.Default, nil
198198
}
199199

200-
func keyedAssociativeListItemToPathElement(a value.Allocator, s *schema.Schema, list *schema.List, index int, child value.Value) (fieldpath.PathElement, error) {
200+
func keyedAssociativeListItemToPathElement(a value.Allocator, s *schema.Schema, list *schema.List, child value.Value) (fieldpath.PathElement, error) {
201201
pe := fieldpath.PathElement{}
202202
if child.IsNull() {
203203
// null entries are illegal.
@@ -225,7 +225,7 @@ func keyedAssociativeListItemToPathElement(a value.Allocator, s *schema.Schema,
225225
return pe, nil
226226
}
227227

228-
func setItemToPathElement(list *schema.List, index int, child value.Value) (fieldpath.PathElement, error) {
228+
func setItemToPathElement(child value.Value) (fieldpath.PathElement, error) {
229229
pe := fieldpath.PathElement{}
230230
switch {
231231
case child.IsMap():
@@ -245,16 +245,15 @@ func setItemToPathElement(list *schema.List, index int, child value.Value) (fiel
245245
}
246246
}
247247

248-
func listItemToPathElement(a value.Allocator, s *schema.Schema, list *schema.List, index int, child value.Value) (fieldpath.PathElement, error) {
249-
if list.ElementRelationship == schema.Associative {
250-
if len(list.Keys) > 0 {
251-
return keyedAssociativeListItemToPathElement(a, s, list, index, child)
252-
}
248+
func listItemToPathElement(a value.Allocator, s *schema.Schema, list *schema.List, child value.Value) (fieldpath.PathElement, error) {
249+
if list.ElementRelationship != schema.Associative {
250+
return fieldpath.PathElement{}, errors.New("invalid indexing of non-associative list")
251+
}
253252

254-
// If there's no keys, then we must be a set of primitives.
255-
return setItemToPathElement(list, index, child)
253+
if len(list.Keys) > 0 {
254+
return keyedAssociativeListItemToPathElement(a, s, list, child)
256255
}
257256

258-
// Use the index as a key for atomic lists.
259-
return fieldpath.PathElement{Index: &index}, nil
257+
// If there's no keys, then we must be a set of primitives.
258+
return setItemToPathElement(child)
260259
}

typed/merge.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ func (w *mergingWalker) indexListPathElements(t *schema.List, list value.List) (
282282
pes := make([]fieldpath.PathElement, 0, length)
283283
for i := 0; i < length; i++ {
284284
child := list.At(i)
285-
pe, err := listItemToPathElement(w.allocator, w.schema, t, i, child)
285+
pe, err := listItemToPathElement(w.allocator, w.schema, t, child)
286286
if err != nil {
287287
errs = append(errs, errorf("element %v: %v", i, err.Error())...)
288288
// If we can't construct the path element, we can't

typed/remove.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ func (w *removingWalker) doList(t *schema.List) (errs ValidationErrors) {
7474
iter := l.RangeUsing(w.allocator)
7575
defer w.allocator.Free(iter)
7676
for iter.Next() {
77-
i, item := iter.Item()
77+
_, item := iter.Item()
7878
// Ignore error because we have already validated this list
79-
pe, _ := listItemToPathElement(w.allocator, w.schema, t, i, item)
79+
pe, _ := listItemToPathElement(w.allocator, w.schema, t, item)
8080
path, _ := fieldpath.MakePath(pe)
8181
// save items on the path when we shouldExtract
8282
// but ignore them when we are removing (i.e. !w.shouldExtract)

typed/tofieldset.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func (v *toFieldSetWalker) doScalar(t *schema.Scalar) ValidationErrors {
9696
func (v *toFieldSetWalker) visitListItems(t *schema.List, list value.List) (errs ValidationErrors) {
9797
for i := 0; i < list.Length(); i++ {
9898
child := list.At(i)
99-
pe, _ := listItemToPathElement(v.allocator, v.schema, t, i, child)
99+
pe, _ := listItemToPathElement(v.allocator, v.schema, t, child)
100100
v2 := v.prepareDescent(pe, t.ElementType)
101101
v2.value = child
102102
errs = append(errs, v2.toFieldSet()...)

typed/validate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func (v *validatingObjectWalker) visitListItems(t *schema.List, list value.List)
129129
pe.Index = &i
130130
} else {
131131
var err error
132-
pe, err = listItemToPathElement(v.allocator, v.schema, t, i, child)
132+
pe, err = listItemToPathElement(v.allocator, v.schema, t, child)
133133
if err != nil {
134134
errs = append(errs, errorf("element %v: %v", i, err.Error())...)
135135
// If we can't construct the path element, we can't

0 commit comments

Comments
 (0)