Skip to content

Commit c3f5f77

Browse files
committed
Add godoc
1 parent 92bb933 commit c3f5f77

17 files changed

+225
-271
lines changed

fieldpath/fromvalue.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ func (w *objectWalker) walk() {
5757
case w.value.IsList():
5858
// If the list were atomic, we'd break here, but we don't have
5959
// a schema, so we can't tell.
60-
l := w.value.AsListInto(w.allocator)
60+
l := w.value.AsListUsing(w.allocator)
6161
defer w.allocator.Free(l)
62-
iter := l.RangeInto(w.allocator)
62+
iter := l.RangeUsing(w.allocator)
6363
defer w.allocator.Free(iter)
6464
for iter.Next() {
6565
i, value := iter.Item()
@@ -73,9 +73,9 @@ func (w *objectWalker) walk() {
7373
// If the map/struct were atomic, we'd break here, but we don't
7474
// have a schema, so we can't tell.
7575

76-
m := w.value.AsMapInto(w.allocator)
76+
m := w.value.AsMapUsing(w.allocator)
7777
defer w.allocator.Free(m)
78-
m.IterateInto(w.allocator, func(k string, val value.Value) bool {
78+
m.IterateUsing(w.allocator, func(k string, val value.Value) bool {
7979
w2 := *w
8080
w2.path = append(w.path, PathElement{FieldName: &k})
8181
w2.value = val
@@ -112,7 +112,7 @@ func (w *objectWalker) GuessBestListPathElement(index int, item value.Value) Pat
112112
return PathElement{Index: &index}
113113
}
114114

115-
m := item.AsMapInto(w.allocator)
115+
m := item.AsMapUsing(w.allocator)
116116
defer w.allocator.Free(m)
117117
var keys value.FieldList
118118
for _, name := range AssociativeListCandidateFieldNames {

typed/helpers.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func listValue(a value.Allocator, val value.Value) (value.List, error) {
162162
if !val.IsList() {
163163
return nil, fmt.Errorf("expected list, got %v", val)
164164
}
165-
return val.AsListInto(a), nil
165+
return val.AsListUsing(a), nil
166166
}
167167

168168
// Returns the map, or an error. Reminder: nil is a valid map and might be returned.
@@ -177,7 +177,7 @@ func mapValue(a value.Allocator, val value.Value) (value.Map, error) {
177177
if !val.IsMap() {
178178
return nil, fmt.Errorf("expected map, got %v", val)
179179
}
180-
return val.AsMapInto(a), nil
180+
return val.AsMapUsing(a), nil
181181
}
182182

183183
func keyedAssociativeListItemToPathElement(a value.Allocator, list *schema.List, index int, child value.Value) (fieldpath.PathElement, error) {
@@ -191,7 +191,7 @@ func keyedAssociativeListItemToPathElement(a value.Allocator, list *schema.List,
191191
return pe, errors.New("associative list with keys may not have non-map elements")
192192
}
193193
keyMap := value.FieldList{}
194-
m := child.AsMapInto(a)
194+
m := child.AsMapUsing(a)
195195
defer a.Free(m)
196196
for _, fieldName := range list.Keys {
197197
if val, ok := m.Get(fieldName); ok {

typed/merge.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ func (w *mergingWalker) visitMapItem(t *schema.Map, out map[string]interface{},
312312
func (w *mergingWalker) visitMapItems(t *schema.Map, lhs, rhs value.Map) (errs ValidationErrors) {
313313
out := map[string]interface{}{}
314314

315-
value.MapZipInto(w.allocator, lhs, rhs, value.Unordered, func(key string, lhsValue, rhsValue value.Value) bool {
315+
value.MapZipUsing(w.allocator, lhs, rhs, value.Unordered, func(key string, lhsValue, rhsValue value.Value) bool {
316316
errs = append(errs, w.visitMapItem(t, out, key, lhsValue, rhsValue)...)
317317
return true
318318
})

typed/remove.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ import (
2020
)
2121

2222
type removingWalker struct {
23-
value value.Value
24-
out interface{}
25-
schema *schema.Schema
26-
toRemove *fieldpath.Set
23+
value value.Value
24+
out interface{}
25+
schema *schema.Schema
26+
toRemove *fieldpath.Set
2727
allocator value.Allocator
2828
}
2929

3030
func removeItemsWithSchema(val value.Value, toRemove *fieldpath.Set, schema *schema.Schema, typeRef schema.TypeRef) value.Value {
3131
w := &removingWalker{
32-
value: val,
33-
schema: schema,
34-
toRemove: toRemove,
32+
value: val,
33+
schema: schema,
34+
toRemove: toRemove,
3535
allocator: value.NewFreelistAllocator(),
3636
}
3737
resolveSchema(schema, typeRef, val, w)
@@ -44,15 +44,15 @@ func (w *removingWalker) doScalar(t *schema.Scalar) ValidationErrors {
4444
}
4545

4646
func (w *removingWalker) doList(t *schema.List) (errs ValidationErrors) {
47-
l := w.value.AsListInto(w.allocator)
47+
l := w.value.AsListUsing(w.allocator)
4848
defer w.allocator.Free(l)
4949
// If list is null, empty, or atomic just return
5050
if l == nil || l.Length() == 0 || t.ElementRelationship == schema.Atomic {
5151
return nil
5252
}
5353

5454
var newItems []interface{}
55-
iter := l.RangeInto(w.allocator)
55+
iter := l.RangeUsing(w.allocator)
5656
defer w.allocator.Free(iter)
5757
for iter.Next() {
5858
i, item := iter.Item()
@@ -74,7 +74,7 @@ func (w *removingWalker) doList(t *schema.List) (errs ValidationErrors) {
7474
}
7575

7676
func (w *removingWalker) doMap(t *schema.Map) ValidationErrors {
77-
m := w.value.AsMapInto(w.allocator)
77+
m := w.value.AsMapUsing(w.allocator)
7878
if m != nil {
7979
defer w.allocator.Free(m)
8080
}

typed/tofieldset.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ type toFieldSetWalker struct {
5656

5757
// Allocate only as many walkers as needed for the depth by storing them here.
5858
spareWalkers *[]*toFieldSetWalker
59-
allocator value.Allocator
59+
allocator value.Allocator
6060
}
6161

6262
func (v *toFieldSetWalker) prepareDescent(pe fieldpath.PathElement, tr schema.TypeRef) *toFieldSetWalker {

typed/validate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func (v *validatingObjectWalker) doScalar(t *schema.Scalar) ValidationErrors {
116116
func (v *validatingObjectWalker) visitListItems(t *schema.List, list value.List) (errs ValidationErrors) {
117117
observedKeys := fieldpath.MakePathElementSet(list.Length())
118118
for i := 0; i < list.Length(); i++ {
119-
child := list.AtInto(v.allocator, i)
119+
child := list.AtUsing(v.allocator, i)
120120
defer v.allocator.Free(child)
121121
var pe fieldpath.PathElement
122122
if t.ElementRelationship != schema.Associative {
@@ -161,7 +161,7 @@ func (v *validatingObjectWalker) doList(t *schema.List) (errs ValidationErrors)
161161
}
162162

163163
func (v *validatingObjectWalker) visitMapItems(t *schema.Map, m value.Map) (errs ValidationErrors) {
164-
m.IterateInto(v.allocator, func(key string, val value.Value) bool {
164+
m.IterateUsing(v.allocator, func(key string, val value.Value) bool {
165165
pe := fieldpath.PathElement{FieldName: &key}
166166
tr := t.ElementType
167167
if sf, ok := t.FindField(key); ok {

value/list.go

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,25 @@ type List interface {
2323
// At returns the item at the given position in the map. It will
2424
// panic if the index is out of range.
2525
At(int) Value
26-
AtInto(Allocator, int) Value
26+
// AtUsing uses the provided allocator and returns the item at the given
27+
// position in the map. It will panic if the index is out of range.
28+
// The returned Value should be given back to the Allocator when no longer needed
29+
// by calling Allocator.Free(Value).
30+
AtUsing(Allocator, int) Value
2731
// Range returns a ListRange for iterating over the items in the list.
2832
Range() ListRange
29-
RangeInto(Allocator) ListRange
30-
31-
// Equals compares the two list, and return true if they are the same, false otherwise.
33+
// RangeUsing uses the provided allocator and returns a ListRange for
34+
// iterating over the items in the list.
35+
// The returned Range should be given back to the Allocator when no longer needed
36+
// by calling Allocator.Free(Value).
37+
RangeUsing(Allocator) ListRange
38+
// Equals compares the two lists, and return true if they are the same, false otherwise.
3239
// Implementations can use ListEquals as a general implementation for this methods.
3340
Equals(List) bool
34-
EqualsInto(Allocator, List) bool
41+
// EqualsUsing uses the provided allocator and compares the two lists, and return true if
42+
// they are the same, false otherwise. Implementations can use ListEqualsUsing as a general
43+
// implementation for this methods.
44+
EqualsUsing(Allocator, List) bool
3545
}
3646

3747
// ListRange represents a single iteration across the items of a list.
@@ -60,23 +70,25 @@ func (_ *emptyRange) Item() (index int, value Value) {
6070
// ListEquals compares two lists lexically.
6171
// WARN: This is a naive implementation, calling lhs.Equals(rhs) is typically the most efficient.
6272
func ListEquals(lhs, rhs List) bool {
63-
return ListEqualsInto(defaultAllocator, lhs, rhs)
73+
return ListEqualsUsing(HeapAllocator, lhs, rhs)
6474
}
6575

66-
func ListEqualsInto(a Allocator, lhs, rhs List) bool {
76+
// ListEqualsUsing uses the provided allocator and compares two lists lexically.
77+
// WARN: This is a naive implementation, calling lhs.EqualsUsing(allocator, rhs) is typically the most efficient.
78+
func ListEqualsUsing(a Allocator, lhs, rhs List) bool {
6779
if lhs.Length() != rhs.Length() {
6880
return false
6981
}
7082

71-
lhsRange := lhs.RangeInto(a)
83+
lhsRange := lhs.RangeUsing(a)
7284
defer a.Free(lhsRange)
73-
rhsRange := rhs.RangeInto(a)
85+
rhsRange := rhs.RangeUsing(a)
7486
defer a.Free(rhsRange)
7587

7688
for lhsRange.Next() && rhsRange.Next() {
7789
_, lv := lhsRange.Item()
7890
_, rv := rhsRange.Item()
79-
if !EqualsInto(a, lv, rv) {
91+
if !EqualsUsing(a, lv, rv) {
8092
return false
8193
}
8294
}
@@ -91,12 +103,15 @@ func ListLess(lhs, rhs List) bool {
91103
// ListCompare compares two lists lexically. The result will be 0 if l==rhs, -1
92104
// if l < rhs, and +1 if l > rhs.
93105
func ListCompare(lhs, rhs List) int {
94-
return ListCompareInto(defaultAllocator, lhs, rhs)
106+
return ListCompareUsing(HeapAllocator, lhs, rhs)
95107
}
96-
func ListCompareInto(a Allocator, lhs, rhs List) int {
97-
lhsRange := lhs.RangeInto(a)
108+
109+
// ListCompareUsing uses the provided allocator and compares two lists lexically. The result will be 0 if l==rhs, -1
110+
// if l < rhs, and +1 if l > rhs.
111+
func ListCompareUsing(a Allocator, lhs, rhs List) int {
112+
lhsRange := lhs.RangeUsing(a)
98113
defer a.Free(lhsRange)
99-
rhsRange := rhs.RangeInto(a)
114+
rhsRange := rhs.RangeUsing(a)
100115
defer a.Free(rhsRange)
101116

102117
for {
@@ -116,7 +131,7 @@ func ListCompareInto(a Allocator, lhs, rhs List) int {
116131
}
117132
_, lv := lhsRange.Item()
118133
_, rv := rhsRange.Item()
119-
if c := CompareInto(a, lv, rv); c != 0 {
134+
if c := CompareUsing(a, lv, rv); c != 0 {
120135
return c
121136
}
122137
// The items are equal; continue.

value/listreflect.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (r listReflect) At(i int) Value {
3434
return mustWrapValueReflect(val.Index(i), nil, nil)
3535
}
3636

37-
func (r listReflect) AtInto(a Allocator, i int) Value {
37+
func (r listReflect) AtUsing(a Allocator, i int) Value {
3838
val := r.Value
3939
return a.allocValueReflect().mustReuse(val.Index(i), nil, nil, nil)
4040
}
@@ -49,10 +49,10 @@ func (r listReflect) Unstructured() interface{} {
4949
}
5050

5151
func (r listReflect) Range() ListRange {
52-
return r.RangeInto(defaultAllocator)
52+
return r.RangeUsing(HeapAllocator)
5353
}
5454

55-
func (r listReflect) RangeInto(a Allocator) ListRange {
55+
func (r listReflect) RangeUsing(a Allocator) ListRange {
5656
length := r.Value.Len()
5757
if length == 0 {
5858
return EmptyRange
@@ -65,13 +65,13 @@ func (r listReflect) RangeInto(a Allocator) ListRange {
6565
}
6666

6767
func (r listReflect) Equals(other List) bool {
68-
return r.EqualsInto(defaultAllocator, other)
68+
return r.EqualsUsing(HeapAllocator, other)
6969
}
70-
func (r listReflect) EqualsInto(a Allocator, other List) bool {
70+
func (r listReflect) EqualsUsing(a Allocator, other List) bool {
7171
if otherReflectList, ok := other.(*listReflect); ok {
7272
return reflect.DeepEqual(r.Value.Interface(), otherReflectList.Value.Interface())
7373
}
74-
return ListEqualsInto(a, &r, other)
74+
return ListEqualsUsing(a, &r, other)
7575
}
7676

7777
type listReflectRange struct {

value/listunstructured.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,23 @@ func (l listUnstructured) At(i int) Value {
2626
return NewValueInterface(l[i])
2727
}
2828

29-
func (l listUnstructured) AtInto(a Allocator, i int) Value {
29+
func (l listUnstructured) AtUsing(a Allocator, i int) Value {
3030
return a.allocValueUnstructured().reuse(l[i])
3131
}
3232

3333
func (l listUnstructured) Equals(other List) bool {
34-
return l.EqualsInto(defaultAllocator, other)
34+
return l.EqualsUsing(HeapAllocator, other)
3535
}
3636

37-
func (l listUnstructured) EqualsInto(a Allocator, other List) bool {
38-
return ListEqualsInto(a, &l, other)
37+
func (l listUnstructured) EqualsUsing(a Allocator, other List) bool {
38+
return ListEqualsUsing(a, &l, other)
3939
}
4040

4141
func (l listUnstructured) Range() ListRange {
42-
return l.RangeInto(defaultAllocator)
42+
return l.RangeUsing(HeapAllocator)
4343
}
4444

45-
func (l listUnstructured) RangeInto(a Allocator) ListRange {
45+
func (l listUnstructured) RangeUsing(a Allocator) ListRange {
4646
if len(l) == 0 {
4747
return EmptyRange
4848
}

0 commit comments

Comments
 (0)