Skip to content

Commit d6641ff

Browse files
committed
Apply feedback
1 parent 1a53920 commit d6641ff

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

value/list.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type List interface {
2929
// Equals compares the two list, and return true if they are the same, false otherwise.
3030
// Implementations can use ListEquals as a general implementation for this methods.
3131
Equals(List) bool
32-
// Recycle returns a value of this type that is no longer needed. The
32+
// Recycle gives back this List once it is no longer needed. The
3333
// value shouldn't be used after this call.
3434
Recycle()
3535
}
@@ -43,7 +43,7 @@ type ListRange interface {
4343
// pointers to the value returned by Item() that escape the iteration loop since they become invalid once either
4444
// Item() or Recycle() is called.
4545
Item() (index int, value Value)
46-
// Recycle returns a ListRange that is no longer needed. The value returned by Item() becomes invalid once this is
46+
// Recycle gives back this ListRange once it is no longer needed. The value returned by Item() becomes invalid once this is
4747
// called.
4848
Recycle()
4949
}

value/map.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ type Map interface {
4545
// with the values from both maps, otherwise it is called with the value of the map that contains the key and nil
4646
// for the map that does not contain the key. Returning false in the closure prematurely stops the iteration.
4747
Zip(other Map, order MapTraverseOrder, fn func(key string, lhs, rhs Value) bool) bool
48-
// Recycle returns a value of this type that is no longer needed. The
48+
// Recycle gives back this Map once it is no longer needed. The
4949
// value shouldn't be used after this call.
5050
Recycle()
5151
}
@@ -121,17 +121,22 @@ func unorderedMapZip(lhs, rhs Map, fn func(key string, lhs, rhs Value) bool) boo
121121

122122
func lexicalKeyOrderedMapZip(lhs, rhs Map, fn func(key string, lhs, rhs Value) bool) bool {
123123
var lhsLength, rhsLength int
124+
var orderedLength int // rough estimate of length of union of map keys
124125
if lhs != nil {
125126
lhsLength = lhs.Length()
127+
orderedLength = lhsLength
126128
}
127129
if rhs != nil {
128130
rhsLength = rhs.Length()
131+
if rhsLength > orderedLength {
132+
orderedLength = rhsLength
133+
}
129134
}
130135
if lhsLength == 0 && rhsLength == 0 {
131136
return true
132137
}
133138

134-
ordered := make([]string, 0, lhsLength+rhsLength)
139+
ordered := make([]string, 0, orderedLength)
135140
if lhs != nil {
136141
lhs.Iterate(func(key string, _ Value) bool {
137142
ordered = append(ordered, key)

value/value.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ type Value interface {
7171
// doesn't allow it).
7272
AsString() string
7373

74-
// Recycle returns a value of this type that is no longer needed. The
74+
// Recycle gives back this Value once it is no longer needed. The
7575
// value shouldn't be used after this call.
7676
Recycle()
7777

0 commit comments

Comments
 (0)