firestore: when decoding into a short slice, try to grow it
There is a case when decoding values that doesn't match the behavior of encoding/json. When decoding an array value that is too large for the slice we create a new slice (https://code.googlesource.com/gocloud/+/v0.34.0/firestore/from_value.go#186). The json code grows the existing slice (https://go.googlesource.com/go/+/go1.11.4/src/encoding/json/decode.go#556).
This is a behavior change, so it should be fixed before leaving beta.
Actually, since firestore knows the length, I believe the firestore code should be
if v.Cap() >= xlen {
v.SetLen(xlen)
} else {
v.Set(reflect.MakeSlice(v.Type(), xlen, xlen))
}
(untested)
@jba Is this a performance / allocation improvement, or are there behavior change that a user might see?
It's both. The input slice will be overwritten instead of being left intact.
Not sure I'm getting the point. The input slice must change its size and be completely overwriten with new values, or you want to union values, like:
result := setReflectFromProtoValue({1}, {2, 3})
fmt.Println(result)
> {1, 2, 3} or {2, 3, 1}
? As I understand, "growing" means "union with old"
Going through old firestore issues -- it looks like this can't be fixed in the current library version since it's now GA, based on what @jba wrote. I'll leave this open as a potential future improvement.