]> Cypherpunks repositories - gostls13.git/commit
encoding/xml: use reflect.Value.Grow
authorDaniel Martí <mvdan@mvdan.cc>
Fri, 7 Apr 2023 17:21:00 +0000 (18:21 +0100)
committerDaniel Martí <mvdan@mvdan.cc>
Fri, 7 Apr 2023 19:49:28 +0000 (19:49 +0000)
commit10c079a0ad2283be3761a47eda6e41bde38fd16b
tree3cbf2b566b2b11b5aeb05286228190d00fe8f483
parent97df9c0b051b6c06bff7ec7e61522e7bbef40c91
encoding/xml: use reflect.Value.Grow

Like https://go.dev/cl/481376 did for encoding/gob,
but now for encoding/xml, which had very similar code.

One minor difference is that encoding/xml now needs a SetLen before the
call to Index, as otherwise we index just past the length.
Still, calling Grow and SetLen is easier to understand,
and avoids needing to make a new zero value.

goos: linux
goarch: amd64
pkg: encoding/xml
cpu: AMD Ryzen 7 PRO 5850U with Radeon Graphics
│     old     │                new                │
│   sec/op    │   sec/op     vs base              │
Unmarshal-8   6.904µ ± 1%   6.980µ ± 1%  +1.10% (p=0.009 n=6)

│     old      │                new                 │
│     B/op     │     B/op      vs base              │
Unmarshal-8   7.656Ki ± 0%   7.586Ki ± 0%  -0.92% (p=0.002 n=6)

│    old     │               new                │
│ allocs/op  │ allocs/op   vs base              │
Unmarshal-8   188.0 ± 0%   185.0 ± 0%  -1.60% (p=0.002 n=6)

Change-Id: Id83feb467a9c59c80c7936aa892780aae7e8b809
Reviewed-on: https://go-review.googlesource.com/c/go/+/483135
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Ian Lance Taylor <iant@google.com>
src/encoding/xml/read.go