@@ -20,18 +20,16 @@ import (
20
20
)
21
21
22
22
type removingWalker struct {
23
- value * value.Value
24
- schema * schema.Schema
25
- lhs * fieldpath.Set
26
- rhs * fieldpath.Set
23
+ value * value.Value
24
+ schema * schema.Schema
25
+ toRemove * fieldpath.Set
27
26
}
28
27
29
- func removeItemsWithSchema (value * value.Value , lhs * fieldpath. Set , rhs * fieldpath.Set , schema * schema.Schema , typeRef schema.TypeRef ) {
28
+ func removeItemsWithSchema (value * value.Value , toRemove * fieldpath.Set , schema * schema.Schema , typeRef schema.TypeRef ) {
30
29
w := & removingWalker {
31
- value : value ,
32
- schema : schema ,
33
- lhs : lhs ,
34
- rhs : rhs ,
30
+ value : value ,
31
+ schema : schema ,
32
+ toRemove : toRemove ,
35
33
}
36
34
resolveSchema (schema , typeRef , w )
37
35
}
@@ -58,10 +56,8 @@ func (w *removingWalker) doStruct(t schema.Struct) ValidationErrors {
58
56
for i , _ := range s .Items {
59
57
item := s .Items [i ]
60
58
pe := fieldpath.PathElement {FieldName : & item .Name }
61
- subsetLHS := w .lhs .WithPrefix (pe )
62
- subsetRHS := w .rhs .WithPrefix (pe )
63
- if ! subsetLHS .Empty () {
64
- removeItemsWithSchema (& s .Items [i ].Value , subsetLHS , subsetRHS , w .schema , fieldTypes [item .Name ])
59
+ if subset := w .toRemove .WithPrefix (pe ); ! subset .Empty () {
60
+ removeItemsWithSchema (& s .Items [i ].Value , subset , w .schema , fieldTypes [item .Name ])
65
61
}
66
62
}
67
63
return nil
@@ -80,13 +76,12 @@ func (w *removingWalker) doList(t schema.List) (errs ValidationErrors) {
80
76
item := l .Items [i ]
81
77
// Ignore error because we have already validated this list
82
78
pe , _ := listItemToPathElement (t , i , item )
83
- subsetLHS := w .lhs .WithPrefix (pe )
84
- subsetRHS := w .rhs .WithPrefix (pe )
85
- if ! subsetLHS .Empty () {
86
- if subsetRHS .Empty () {
87
- continue
88
- }
89
- removeItemsWithSchema (& l .Items [i ], subsetLHS , subsetRHS , w .schema , t .ElementType )
79
+ path , _ := fieldpath .MakePath (pe )
80
+ if w .toRemove .Has (path ) {
81
+ continue
82
+ }
83
+ if subset := w .toRemove .WithPrefix (pe ); ! subset .Empty () {
84
+ removeItemsWithSchema (& l .Items [i ], subset , w .schema , t .ElementType )
90
85
}
91
86
newItems = append (newItems , l .Items [i ])
92
87
}
@@ -106,13 +101,12 @@ func (w *removingWalker) doMap(t schema.Map) ValidationErrors {
106
101
for i , _ := range m .Items {
107
102
item := m .Items [i ]
108
103
pe := fieldpath.PathElement {FieldName : & item .Name }
109
- subsetLHS := w .lhs .WithPrefix (pe )
110
- subsetRHS := w .rhs .WithPrefix (pe )
111
- if ! subsetLHS .Empty () {
112
- if subsetRHS .Empty () {
113
- continue
114
- }
115
- removeItemsWithSchema (& m .Items [i ].Value , subsetLHS , subsetRHS , w .schema , t .ElementType )
104
+ path , _ := fieldpath .MakePath (pe )
105
+ if w .toRemove .Has (path ) {
106
+ continue
107
+ }
108
+ if subset := w .toRemove .WithPrefix (pe ); ! subset .Empty () {
109
+ removeItemsWithSchema (& m .Items [i ].Value , subset , w .schema , t .ElementType )
116
110
}
117
111
newMap .Set (item .Name , m .Items [i ].Value )
118
112
}
0 commit comments