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 <joetsai@digital-static.net>
Trust: Joe Tsai <joetsai@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
This commit is contained in:
Joe Tsai 2020-10-19 20:32:27 -07:00
parent f0affd4123
commit 44626bc40b
2 changed files with 3 additions and 3 deletions

View File

@ -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

View File

@ -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