encoding/gob: update decgen to generate current dec_helpers

I edited dec_helpers.go without realizing that it is a generated file.
Fix the generator to generate the current version (which generates
a small comment change).

Change-Id: I70e3bc78eb0728d23c08972611218f288dc1d29c
Reviewed-on: https://go-review.googlesource.com/c/go/+/479117
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Andrew Ekstedt <andrew.ekstedt@gmail.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
This commit is contained in:
Ian Lance Taylor 2023-03-23 17:38:05 -07:00 committed by Gopher Robot
parent bd7b19356f
commit c994067e5b
2 changed files with 23 additions and 0 deletions

View File

@ -359,6 +359,7 @@ func decStringSlice(state *decoderState, v reflect.Value, length int, ovfl error
errorf("decoding string array or slice: length exceeds input size (%d elements)", length) errorf("decoding string array or slice: length exceeds input size (%d elements)", length)
} }
if i >= len(slice) { if i >= len(slice) {
// This is a slice that we only partially allocated.
growSlice(v, &slice, length) growSlice(v, &slice, length)
} }
u := state.decodeUint() u := state.decodeUint()

View File

@ -180,6 +180,7 @@ func main() {
fmt.Fprintf(&b, arrayHelper, t.lower, t.upper) fmt.Fprintf(&b, arrayHelper, t.lower, t.upper)
fmt.Fprintf(&b, sliceHelper, t.lower, t.upper, t.decoder) fmt.Fprintf(&b, sliceHelper, t.lower, t.upper, t.decoder)
} }
fmt.Fprintf(&b, trailer)
source, err := format.Source(b.Bytes()) source, err := format.Source(b.Bytes())
if err != nil { if err != nil {
log.Fatal("source format error:", err) log.Fatal("source format error:", err)
@ -236,8 +237,29 @@ func dec%[2]sSlice(state *decoderState, v reflect.Value, length int, ovfl error)
if state.b.Len() == 0 { if state.b.Len() == 0 {
errorf("decoding %[1]s array or slice: length exceeds input size (%%d elements)", length) errorf("decoding %[1]s array or slice: length exceeds input size (%%d elements)", length)
} }
if i >= len(slice) {
// This is a slice that we only partially allocated.
growSlice(v, &slice, length)
}
%[3]s %[3]s
} }
return true return true
} }
` `
const trailer = `
// growSlice is called for a slice that we only partially allocated,
// to grow it up to length.
func growSlice[E any](v reflect.Value, ps *[]E, length int) {
var zero E
s := *ps
s = append(s, zero)
cp := cap(s)
if cp > length {
cp = length
}
s = s[:cp]
v.Set(reflect.ValueOf(s))
*ps = s
}
`