diff --git a/spanner/value.go b/spanner/value.go index 63d881865a0f..86d9f71b250a 100644 --- a/spanner/value.go +++ b/spanner/value.go @@ -872,8 +872,9 @@ func decodeStringArray(pb *proto3.ListValue) ([]string, error) { return nil, errNilListValue("STRING") } a := make([]string, len(pb.Values)) + st := stringType() for i, v := range pb.Values { - if err := decodeValue(v, stringType(), &a[i]); err != nil { + if err := decodeValue(v, st, &a[i]); err != nil { return nil, errDecodeArrayElement(i, v, "STRING", err) } } diff --git a/spanner/value_benchmarks_test.go b/spanner/value_benchmarks_test.go index a8d89a487a2b..0d95ab9de259 100644 --- a/spanner/value_benchmarks_test.go +++ b/spanner/value_benchmarks_test.go @@ -115,6 +115,7 @@ func BenchmarkDecodeArray(b *testing.B) { {"DateDirect", decodeArray_Date_direct}, {"DateFunc", decodeArray_Date_func}, {"DateReflect", decodeArray_Date_reflect}, + {"StringDecodeStringArray", decodeStringArrayWrap}, {"StringDirect", decodeArray_String_direct}, {"StringFunc", decodeArray_String_func}, {"StringReflect", decodeArray_String_reflect}, @@ -154,6 +155,12 @@ func decodeArray_Date_reflect(pb *proto3.ListValue) { } } +func decodeStringArrayWrap(pb *proto3.ListValue) { + if _, err := decodeStringArray(pb); err != nil { + panic(err) + } +} + func decodeArray_String_direct(pb *proto3.ListValue) { a := make([]string, len(pb.Values)) t := stringType()