mirror of
https://github.com/golang/go.git
synced 2025-05-05 23:53:05 +00:00
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:
parent
bd7b19356f
commit
c994067e5b
@ -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)
|
||||
}
|
||||
if i >= len(slice) {
|
||||
// This is a slice that we only partially allocated.
|
||||
growSlice(v, &slice, length)
|
||||
}
|
||||
u := state.decodeUint()
|
||||
|
@ -180,6 +180,7 @@ func main() {
|
||||
fmt.Fprintf(&b, arrayHelper, t.lower, t.upper)
|
||||
fmt.Fprintf(&b, sliceHelper, t.lower, t.upper, t.decoder)
|
||||
}
|
||||
fmt.Fprintf(&b, trailer)
|
||||
source, err := format.Source(b.Bytes())
|
||||
if err != nil {
|
||||
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 {
|
||||
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
|
||||
}
|
||||
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
|
||||
}
|
||||
`
|
||||
|
Loading…
x
Reference in New Issue
Block a user