@@ -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
122122func 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 )
0 commit comments