From 44626bc40ba7274db25d1b3a00cc0f791b774dc1 Mon Sep 17 00:00:00 2001 From: Joe Tsai Date: Mon, 19 Oct 2020 20:32:27 -0700 Subject: [PATCH] internal/cmd/generate-types: move variable declaration Move the declaration of the slice variable as close to its actual use as possible. Change-Id: Ibe26460b5ca81edbed1073b32faf1c5f5d2c922a Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/263719 Trust: Joe Tsai Trust: Joe Tsai Reviewed-by: Damien Neil --- internal/cmd/generate-types/impl.go | 2 +- internal/impl/codec_gen.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/cmd/generate-types/impl.go b/internal/cmd/generate-types/impl.go index 96996f21..2113629d 100644 --- a/internal/cmd/generate-types/impl.go +++ b/internal/cmd/generate-types/impl.go @@ -422,7 +422,6 @@ func append{{.Name}}SliceValidateUTF8(b []byte, p pointer, f *coderFieldInfo, _ // consume{{.Name}}SliceValidateUTF8 wire decodes a []{{.GoType}} pointer as a repeated {{.Name}}. func consume{{.Name}}SliceValidateUTF8(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, _ unmarshalOptions) (out unmarshalOutput, err error) { - sp := p.{{.GoType.PointerMethod}}Slice() if wtyp != {{.WireType.Expr}} { return out, errUnknown } @@ -433,6 +432,7 @@ func consume{{.Name}}SliceValidateUTF8(b []byte, p pointer, wtyp protowire.Type, if !utf8.Valid{{if eq .Name "String"}}String{{end}}(v) { return out, errInvalidUTF8{} } + sp := p.{{.GoType.PointerMethod}}Slice() *sp = append(*sp, {{.ToGoType}}) out.n = n return out, nil diff --git a/internal/impl/codec_gen.go b/internal/impl/codec_gen.go index 98aaf2d6..bb14c13e 100644 --- a/internal/impl/codec_gen.go +++ b/internal/impl/codec_gen.go @@ -5174,7 +5174,6 @@ func appendStringSliceValidateUTF8(b []byte, p pointer, f *coderFieldInfo, _ mar // consumeStringSliceValidateUTF8 wire decodes a []string pointer as a repeated String. func consumeStringSliceValidateUTF8(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, _ unmarshalOptions) (out unmarshalOutput, err error) { - sp := p.StringSlice() if wtyp != protowire.BytesType { return out, errUnknown } @@ -5185,6 +5184,7 @@ func consumeStringSliceValidateUTF8(b []byte, p pointer, wtyp protowire.Type, f if !utf8.ValidString(v) { return out, errInvalidUTF8{} } + sp := p.StringSlice() *sp = append(*sp, v) out.n = n return out, nil @@ -5514,7 +5514,6 @@ func appendBytesSliceValidateUTF8(b []byte, p pointer, f *coderFieldInfo, _ mars // consumeBytesSliceValidateUTF8 wire decodes a [][]byte pointer as a repeated Bytes. func consumeBytesSliceValidateUTF8(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, _ unmarshalOptions) (out unmarshalOutput, err error) { - sp := p.BytesSlice() if wtyp != protowire.BytesType { return out, errUnknown } @@ -5525,6 +5524,7 @@ func consumeBytesSliceValidateUTF8(b []byte, p pointer, wtyp protowire.Type, f * if !utf8.Valid(v) { return out, errInvalidUTF8{} } + sp := p.BytesSlice() *sp = append(*sp, append(emptyBuf[:], v...)) out.n = n return out, nil