Skip to content

Commit 3faeeaf

Browse files
author
Antoine Pelisse
committed
Use PathElementSet rather than map[PathElement.String()]
1 parent 13ba6db commit 3faeeaf

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

typed/validate.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func (v *validatingObjectWalker) doScalar(t *schema.Scalar) ValidationErrors {
142142
}
143143

144144
func (v *validatingObjectWalker) visitListItems(t *schema.List, list *value.List) (errs ValidationErrors) {
145-
observedKeys := map[string]struct{}{}
145+
observedKeys := fieldpath.PathElementSet{}
146146
for i, child := range list.Items {
147147
pe, err := listItemToPathElement(t, i, child)
148148
if err != nil {
@@ -152,11 +152,10 @@ func (v *validatingObjectWalker) visitListItems(t *schema.List, list *value.List
152152
// this element.
153153
continue
154154
}
155-
keyStr := pe.String()
156-
if _, found := observedKeys[keyStr]; found {
157-
errs = append(errs, v.errorf("duplicate entries for key %v", keyStr)...)
155+
if observedKeys.Has(pe) {
156+
errs = append(errs, v.errorf("duplicate entries for key %v", pe.String())...)
158157
}
159-
observedKeys[keyStr] = struct{}{}
158+
observedKeys.Insert(pe)
160159
v2 := v.prepareDescent(pe, t.ElementType)
161160
v2.value = child
162161
errs = append(errs, v2.validate()...)

0 commit comments

Comments
 (0)