aboutsummaryrefslogtreecommitdiff
path: root/src/encoding
AgeCommit message (Collapse)Author
2023-09-07encoding/xml: use reflect.Value.Bytes on addressable arraysDaniel Martí
Since #47066 was accepted and implemented, reflect.Value.Bytes can be called directly on addressable arrays, so there is no longer a need to go through a slice first. Change-Id: I04d50ddb1b38e7a37fee3dc8be1bd03b22a06a1c Reviewed-on: https://go-review.googlesource.com/c/go/+/526357 Reviewed-by: Joseph Tsai <joetsai@digital-static.net> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2023-09-07encoding/gob: fix typo in comment for decAllocJes Cok
Change-Id: I89c607ee40358d6d650ba0ea1f05ce7d1df698bd GitHub-Last-Rev: e78a37118009dbd9468a0f656ad66b989f7c5ada GitHub-Pull-Request: golang/go#62319 Reviewed-on: https://go-review.googlesource.com/c/go/+/523376 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: qiulaidongfeng <2645477756@qq.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Rob Pike <r@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-09-07encoding/gob: make comment more idiomatic for *Encoder.writerJes Cok
Change-Id: I89a4d7f4af8dfb67a35647283be6c1d2965595f5 GitHub-Last-Rev: f7c11c156cd0c1d7e9e811c5eb2d19d233c568dd GitHub-Pull-Request: golang/go#62389 Reviewed-on: https://go-review.googlesource.com/c/go/+/524735 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: qiulaidongfeng <2645477756@qq.com> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Rob Pike <r@golang.org>
2023-09-07encoding/gob: swap 'err, i' to correct verbs in decUint8SliceJes Cok
Change-Id: I76b2dd45179f65e9ed4f1d0f597ca59e49b59a85 GitHub-Last-Rev: b4171e6b836f948ff2973d91a19f0fd58cc8faea GitHub-Pull-Request: golang/go#62374 Reviewed-on: https://go-review.googlesource.com/c/go/+/524356 Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Rob Pike <r@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-09-03encoding: show the alphabet for base32 and base64Joe Tsai
There is not a great reason to hide the alphabet used for StdEncoding, HexEncoding, and URLEncoding. Although this is specified in RFC 4748, showing it in GoDoc saves an extra click from going to the RFC itself to see the alphabet being used. Also, split exported and unexported constants apart so that GoDoc renders more cleanly. Fixes #55126 Change-Id: I03bfa607fb6c3df7f757e33fc0f4ec2b233de1a1 Reviewed-on: https://go-review.googlesource.com/c/go/+/525296 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Joseph Tsai <joetsai@digital-static.net> Auto-Submit: Joseph Tsai <joetsai@digital-static.net>
2023-09-02encoding/gob: add comma in field comment of userTypeInfo for consistencyJes Cok
Change-Id: I80c494a357195dad3ade98fcce0a6883303777ce GitHub-Last-Rev: a30615f3733fb0a43628cc81df7ad286e789b445 GitHub-Pull-Request: golang/go#62422 Reviewed-on: https://go-review.googlesource.com/c/go/+/524998 Run-TryBot: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com>
2023-08-31all: rewrite internal/saferio.SliceCap using generics and add func ↵Jes Cok
SliceCapWithSize Change-Id: I265173bf2722796c4be545c968efef3a1a6f7a7d GitHub-Last-Rev: 04d95cdd615f906167545f246f707e1440c39374 GitHub-Pull-Request: golang/go#62365 Reviewed-on: https://go-review.googlesource.com/c/go/+/524257 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-08-30encoding/xml: overriding by empty namespace when no new name declarationxuri
The unmarshal and marshal XML text should be consistent if not modified deserialize variable. Fixes #61881 Change-Id: I475f7b05211b618685597d3ff20b97e3bbeaf8f8 GitHub-Last-Rev: 6831c770c384831798cb1c6dc4674e5d4caa5e3c GitHub-Pull-Request: golang/go#58401 Reviewed-on: https://go-review.googlesource.com/c/go/+/466295 Reviewed-by: ri xu <xuri.me@gmail.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Russ Cox <rsc@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-08-30encoding/asn1: use reflect.TypeFor for known typesapocelipes
For #60088 Change-Id: I4b2a5c6c59ef26361f343052a4ddaabde5d3bc94 GitHub-Last-Rev: d519835ad592efab031917c83483e5dcbeff1c3a GitHub-Pull-Request: golang/go#62370 Reviewed-on: https://go-review.googlesource.com/c/go/+/524259 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Roland Shoemaker <roland@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com>
2023-08-29encoding/json: adjust comment about encoding \b and \fChristian Höppner
The encoding for the control characters \b and \f was changed in http://go.dev/cl/521675. This CL adjusts the corresponding comment about encoding bytes < 0x20. Change-Id: I83b7311e4fa0731f6601ca64a66042425b4cecac Reviewed-on: https://go-review.googlesource.com/c/go/+/523435 Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Joseph Tsai <joetsai@digital-static.net> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
2023-08-25encoding/json: modernize testsJoe Tsai
There are no changes to what is being tested. No test cases were removed or added. Changes made: * Use a local implementation of test case position marking. See #52751. * Use consistent names for all test tables and variables. * Generally speaking, follow modern Go style guide for tests. * Move global tables local to the test function if possible. * Make every table entry run in a distinct testing.T.Run. The purpose of this change is to make it easier to perform v1-to-v2 development where we want v2 to support close to bug-for-bug compatibility when running in v1 mode. Annotating each test case with the location of the test data makes it easier to jump directly to the test data itself and understand why this particular case is failing. Having every test case run in its own t.Run makes it easier to isolate a particular failing test and work on fixing the code until that test case starts to pass again. Unfortunately, many tests are annotated with an empty name. An empty name is better than nothing, since the testing framework auto assigns a numeric ID for duplicate names. It is not worth the trouble to give descriptive names to each of the thousands of test cases. Change-Id: I43905f35249b3d77dfca234b9c7808d40e225de8 Reviewed-on: https://go-review.googlesource.com/c/go/+/522880 Auto-Submit: Joseph Tsai <joetsai@digital-static.net> Run-TryBot: Joseph Tsai <joetsai@digital-static.net> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Damien Neil <dneil@google.com>
2023-08-25encoding/json: avoid allocation when decoding number typeskorzhao
In CL 345488, we optimized strconv.ParseXXX for []byte arguments. That allows immediate casting of a []byte to a string that does not escape to be copied on the stack. Performance: goos: darwin goarch: arm64 pkg: encoding/json old sec/op new sec/op delta CodeUnmarshal-10 3.019m ± 6% 2.865m ± 10% -5.10% (p=0.043 n=10) CodeUnmarshalReuse-10 2.528m ± 4% 2.274m ± 13% -10.03% (p=0.009 n=10) geomean 2.762m 2.553m -7.60% old B/s new B/s delta CodeUnmarshal-10 613.1Mi ± 5% 646.0Mi ± 9% +5.37% (p=0.043 n=10) CodeUnmarshalReuse-10 732.1Mi ± 4% 813.7Mi ± 12% +11.15% (p=0.009 n=10) geomean 669.9Mi 725.0Mi +8.22% old B/op new B/op delta CodeUnmarshal-10 2.782Mi ± 0% 1.918Mi ± 0% -31.04% (p=0.000 n=10) CodeUnmarshalReuse-10 1600.8Ki ± 0% 713.3Ki ± 0% -55.44% (p=0.000 n=10) geomean 2.085Mi 1.156Mi -44.57% old allocs/op new allocs/op delta CodeUnmarshal-10 91.31k ± 0% 39.99k ± 0% -56.20% (p=0.000 n=10) CodeUnmarshalReuse-10 76.58k ± 0% 25.23k ± 0% -67.06% (p=0.000 n=10) geomean 83.62k 31.76k -62.02% Change-Id: I208c57089040daee0f9d979d1df725e3acf34f81 Reviewed-on: https://go-review.googlesource.com/c/go/+/518277 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Joseph Tsai <joetsai@digital-static.net> Run-TryBot: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
2023-08-25encoding/json: optimize Marshal for mapskorzhao
Optimize marshaling of maps by using slices.SortFunc. This drops an unnecessary field from reflectWithString, which also reduces the cost of each swap operation. benchmark old ns/op new ns/op delta BenchmarkMarshalMap-10 228 139 -39.24% benchmark old allocs new allocs delta BenchmarkMarshalMap-10 11 8 -27.27% benchmark old bytes new bytes delta BenchmarkMarshalMap-10 432 232 -46.30% Change-Id: Ic2ba7a1590863c7536305c6f6536372b26ec9b0c Reviewed-on: https://go-review.googlesource.com/c/go/+/515176 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: qiulaidongfeng <2645477756@qq.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2023-08-23encoding/json: encode \b and \f as '\b' and '\f' in JSON stringsJoe Tsai
According to RFC 8259, there are exactly 5 control characters that have a shorter escape sequence than the generic \uXXXX format. Over the years, we added ad-hoc support for the short sequences: * https://go.dev/cl/4678046 supports \r and \n * https://go.dev/cl/162340043 supports \t This CL completes the set by supporting \b and \f. This may change the encoding of strings in relatively rare cases, but is a permissible change since the Go 1 compatibility document does not guarantee that "json" produces byte-for-byte identical outputs. In fact, we have made even more observable output changes in the past such as with https://go.dev/cl/30371 which changes the representation of many JSON numbers. This change is to prepare the path forward for a potential v2 "json" package, which has more consistent encoding of JSON strings. Change-Id: I11102a0602dfb1a0c14eaad82ed23e8df7553c6b Reviewed-on: https://go-review.googlesource.com/c/go/+/521675 Auto-Submit: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: Bryan Mills <bcmills@google.com>
2023-08-19encoding/csv: correct Column docsIan Lance Taylor
For #44221 Fixes #62147 Change-Id: Ibcc0d11c8253f51a8f5771791ea4173a38a61950 Reviewed-on: https://go-review.googlesource.com/c/go/+/520917 Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2023-08-19encoding/gob: prevent panic from index out of range in Decoder.typeStringAndy Pan
I believe this bug is introduced by CL 460543 which optimizes the allocations by changing the type of `idToType` from map to slice, but didn't update the access code in `Decoder.typeString` that is safe for map but not for slice. Fixes #62117 Change-Id: I0f2e4cc2f34c54dada1f83458ba512a6fde6dcbe Reviewed-on: https://go-review.googlesource.com/c/go/+/520757 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Andy Pan <panjf2000@gmail.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com>
2023-08-19encoding: optimize growth behavior in Encoding.AppendDecodeJoe Tsai
The Encoding.DecodedLen API only returns the maximum length of the expected decoded output, since it does not know about padding. Since we have the input, we can do better by computing the input length without padding, and then perform the DecodedLen calculation as if there were no padding. This avoids over-growing the destination slice if possible. Over-growth is still possible since the input may contain ignore characters like newlines and carriage returns, but those a rarely encountered in practice. Change-Id: I38b8f91de1f4fbd3a7128c491a25098bd385cf74 Reviewed-on: https://go-review.googlesource.com/c/go/+/520267 Run-TryBot: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-08-18encoding/json: use base64.Encoding.AppendEncodeAndy Pan
For #53693 Change-Id: I6a428a4a10a2e2efa03296f539e190f0743c1f46 Reviewed-on: https://go-review.googlesource.com/c/go/+/520755 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Andy Pan <panjf2000@gmail.com>
2023-08-18encoding: require unique alphabet for base32 and base64Joe Tsai
In order for decoding to faithfully reproduce the encoded input, the symbols must be unique (i.e., provide a bijective mapping). Thus, reject duplicate symbols in NewEncoding. As a minor optimization, modify WithPadding to use the decodeMap to quickly check whether the padding character is used in O(1) instead of O(32) or O(64). Change-Id: I5631f6ff9335c35d59d020dc0e307e3520786fbc Reviewed-on: https://go-review.googlesource.com/c/go/+/520335 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Joseph Tsai <joetsai@digital-static.net> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Joseph Tsai <joetsai@digital-static.net>
2023-08-17encoding: reject negative runes in Encoding.WithPaddingJoe Tsai
A negative rune (other than NoPadding) makes no semantic sense. Doing so relies on integer overflow of converting a rune to a byte and would thus be equivalent to passing the positive byte value of byte(padding). This may cause existing code to panic. An alternative is treat negative runes as equivalent to NoPadding. However, the code already panics to report erroneous padding values, so this is in line with the existing API. Change-Id: I02499705519581598adc0c8525d90e25278dc056 Reviewed-on: https://go-review.googlesource.com/c/go/+/505236 Auto-Submit: Joseph Tsai <joetsai@digital-static.net> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2023-08-17encoding: add AppendEncode and AppendDecodeJoe Tsai
Implement append-like equivalent of Encode and Decode functions. Fixes #53693 Change-Id: I79d8d834e3c8f77fad32be2fd391e33d4d1527ea Reviewed-on: https://go-review.googlesource.com/c/go/+/504884 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Joseph Tsai <joetsai@digital-static.net> Auto-Submit: Joseph Tsai <joetsai@digital-static.net>
2023-08-14encoding/json: declare hex as a constJes Cok
hex is in fact immutable, declare it as a const to avoid accidental modification, also for consistency with other packages. Change-Id: I99f292e98c82d4c4526e46c9897d154d0c073da5 GitHub-Last-Rev: d2f06965e7e03df470d8c3c8882619187abf1609 GitHub-Pull-Request: golang/go#62011 Reviewed-on: https://go-review.googlesource.com/c/go/+/519155 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2023-08-07all: add a few more godoc linksDaniel Martí
Over the past few months as I read the standard library's documentation I kept finding spots where godoc links would have helped me. I kept adding to a stash of changes to fix them up bit by bit. The stash has grown big enough by now, and we're nearing a release, so I think it's time to merge to avoid git conflicts or bit rot. Note that a few sentences are slightly reworded, since "implements the Fooer interface" can just be "implements [Fooer]" now that the link provides all the context needed to the user. Change-Id: I01c31d3d3ff066d06aeb44f545f8dd0fb9a8d998 Reviewed-on: https://go-review.googlesource.com/c/go/+/508395 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-08-07encoding/base32: optimize Encodekorzhao
Converts the 5 x 8-bit source byte to two 32-bit integers. This will reduce the number of shift operations. benchmark old ns/op new ns/op delta BenchmarkEncode-10 9005 4426 -50.85% BenchmarkEncodeToString-10 10739 6155 -42.69% benchmark old MB/s new MB/s speedup BenchmarkEncode-10 909.69 1850.81 2.03x BenchmarkEncodeToString-10 762.84 1331.02 1.74x Change-Id: I9418d3436b73f94a4eb4b2b525e4f83612ff4d47 Reviewed-on: https://go-review.googlesource.com/c/go/+/514095 Reviewed-by: Michael Knyszek <mknyszek@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2023-08-07encoding/xml, image/jpeg, image/png: use the builtin min functionapocelipes
Change-Id: I9bafc7aa4e20e7cd994b75e7576156ca68f4fc8b GitHub-Last-Rev: e037f689bddd0ef03a6ad38982fe98b4c26aaede GitHub-Pull-Request: golang/go#61746 Reviewed-on: https://go-review.googlesource.com/c/go/+/515855 Run-TryBot: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2023-08-03encoding/gob: skip TestLargeSlice on machines with small address spacemiller
The encoding/gob.TestLargeSlice test needs too much virtual memory to run reliably on machines with a small address space, for example the plan9-arm builders where user processes only have 1 gigabyte. Fixes #60284 Change-Id: Ied88630e5ec6685e14d2060ae316abca1619f9b5 Reviewed-on: https://go-review.googlesource.com/c/go/+/496138 Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: David du Colombier <0intro@gmail.com> Run-TryBot: David du Colombier <0intro@gmail.com>
2023-08-02encoding/json: adjust comment to keep the same style as comment aboveJes Cok
Change-Id: Id47d32d18031883b874bba4cf8541f75c5d7f9db GitHub-Last-Rev: 98c671c00c112e7bdf70b2f901a4f7682f922725 GitHub-Pull-Request: golang/go#61711 Reviewed-on: https://go-review.googlesource.com/c/go/+/515215 Reviewed-by: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Auto-Submit: Russ Cox <rsc@golang.org> Reviewed-by: David Chase <drchase@google.com>
2023-08-01encoding/json: replace "between or" with "between and" in commentJes Cok
Change-Id: Id19a15f9367de10e08a9ec22a8cb50c58d517906 GitHub-Last-Rev: f413d71c9ad0f2efc0b4811c7188cc2caa9c1de0 GitHub-Pull-Request: golang/go#61701 Reviewed-on: https://go-review.googlesource.com/c/go/+/514976 Reviewed-by: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Auto-Submit: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-08-01encoding/json: use reflect.TypeFor for known typesIan Lance Taylor
For #60088 Change-Id: I2e471c76de62944b14472966b63f5778124b9b8b Reviewed-on: https://go-review.googlesource.com/c/go/+/514655 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> Run-TryBot: Joseph Tsai <joetsai@digital-static.net> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
2023-08-01encoding/xml: use reflect.TypeFor for known typesIan Lance Taylor
For #60088 Change-Id: Ib2589b994d304cca1f2e2081639959d80818ac7f Reviewed-on: https://go-review.googlesource.com/c/go/+/514639 Run-TryBot: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: David Chase <drchase@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
2023-08-01encoding/gob: use reflect.TypeFor for known typesIan Lance Taylor
This avoids several mildly confusing Elem calls. For #60088 Change-Id: If7b83d2ab10537c7e886a035b43cb272130c1669 Reviewed-on: https://go-review.googlesource.com/c/go/+/514455 Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Rob Pike <r@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2023-07-31encoding/json: optimize Unmarshal for mapskorzhao
benchmark old ns/op new ns/op delta BenchmarkUnmarshalMap-10 218 172 -21.28% benchmark old allocs new allocs delta BenchmarkUnmarshalMap-10 15 12 -20.00% benchmark old bytes new bytes delta BenchmarkUnmarshalMap-10 328 256 -21.95% Change-Id: Ie20ab62731c752eb0040c6d1591fedd7d12b1e0c Reviewed-on: https://go-review.googlesource.com/c/go/+/514100 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2023-07-29encoding/json: replace dead link in appendStringkorzhao
Change-Id: I534698008b46b23352d9f1fed891fd96dc0947b7 Reviewed-on: https://go-review.googlesource.com/c/go/+/507115 Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com>
2023-07-27reflect: deprecate PtrToqiulaidongfeng
Replace reflect.PtrTo with reflect.PointerTo. Fixes #59599 Change-Id: I49407193e2050543ef983cd637703acc682d9f51 Change-Id: I49407193e2050543ef983cd637703acc682d9f51 GitHub-Last-Rev: 7bc9ccf1dcb4b444406430b451ad4c47c6ec1be2 GitHub-Pull-Request: golang/go#61440 Reviewed-on: https://go-review.googlesource.com/c/go/+/511035 Run-TryBot: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-07-26encoding/base32: reduce overflow risk when calc encode/decode lenchanxuehong
Same as https://go-review.googlesource.com/c/go/+/510635, reduces risk of overflow Change-Id: I18f5560d73af76c3e853464a89ad7e42dbbd5894 GitHub-Last-Rev: 652c8c6712886184e59a110c3fa1e6dcb643d93b GitHub-Pull-Request: golang/go#61547 Reviewed-on: https://go-review.googlesource.com/c/go/+/512200 Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2023-07-21encoding/base64: reduce the overflow risk when computing encode/decode lengthchanxuehong
Change-Id: I0a55cdc38ae496e2070f0b9ef317a41f82352afd GitHub-Last-Rev: c19527a26b0778cbb4548f49e1e365102709f068 GitHub-Pull-Request: golang/go#61407 Reviewed-on: https://go-review.googlesource.com/c/go/+/510635 Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Heschi Kreinick <heschi@google.com>
2023-07-18all: fix typosJes Cok
Change-Id: I510b0a4bf3472d937393800dd57472c30beef329 GitHub-Last-Rev: 8d289b73a37bd86080936423d981d21e152aaa33 GitHub-Pull-Request: golang/go#60960 Reviewed-on: https://go-review.googlesource.com/c/go/+/505398 Auto-Submit: Robert Findley <rfindley@google.com> Reviewed-by: Robert Findley <rfindley@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Robert Findley <rfindley@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-06-27encoding: document that base32 and base64 do not use UTF-8Joe Tsai
The invention of base32 and base64 predates the invention of UTF-8 and was never meant to output valid UTF-8. By default, the output is always valid ASCII (and thus valid UTF-8) except when the user specifies an alphabet or padding value that is larger than '\x7f'. If that is done, then the exact byte symbol is used rather than the UTF-8 encoding. Fixes #60689 Change-Id: I4ec88d974ec0658ad1a578bbd65a809e27c73ea7 Reviewed-on: https://go-review.googlesource.com/c/go/+/505237 Run-TryBot: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-06-20encoding/binary: on invalid type return -1 from SizeIan Lance Taylor
Size is defined as returning -1 if the type is not fixed-size. Before this CL cases like Size((*[]int)(nil)) would crash. Fixes #60892 Change-Id: Iee8e20a0aee24b542b78cb4160c3b2c5a3eb02c2 Reviewed-on: https://go-review.googlesource.com/c/go/+/504575 Auto-Submit: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Robert Griesemer <gri@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com>
2023-05-25encoding/json: document unsupported float valuesSean Liao
Fixes #59627 Change-Id: Icd6a9803e213596de6136ec980b0a352c450e6f7 Reviewed-on: https://go-review.googlesource.com/c/go/+/496142 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2023-05-23encoding: document when marshaling methods can be addedSean Liao
Fixes #10275 Change-Id: I2b3d54f3eb0f85d65324ddc3c3b2a797d42a16c9 Reviewed-on: https://go-review.googlesource.com/c/go/+/496537 Run-TryBot: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2023-05-17encoding/xml: wrap charsetReader errorsThuy Linh Luu
This change wraps the errors from the CharsetReader function so the caller can distinguish different error conditions. Context: I have an XML file with an unknown encoding which I like to handle separately. I like to use the CharsetReader for this but the error type has not been forwarded. Change-Id: I6739a0dee04ec376cd20536be2806ce7f50c5213 GitHub-Last-Rev: ada9dd510f9a5b7f8c9473f6864077e0ed6898bd GitHub-Pull-Request: golang/go#60199 Reviewed-on: https://go-review.googlesource.com/c/go/+/494897 Reviewed-by: Heschi Kreinick <heschi@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org>
2023-05-10encoding/csv: update doc comment of Read methodIvoGoman
This updates the doc comment to reflect the behavior of the method. On error the method returns a partial result. Fixes #59991 Change-Id: I71e9dfa37e0488c85abd3eeede2a1a34cb74239b GitHub-Last-Rev: 389488e5364dc939f0cbd11f99eb56001b5237a2 GitHub-Pull-Request: golang/go#60084 Reviewed-on: https://go-review.googlesource.com/c/go/+/494055 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Benny Siegert <bsiegert@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com>
2023-04-20std: fix various nilness findingsAlan Donovan
Found by running $ go run golang.org/x/tools/go/analysis/passes/nilness/cmd/nilness@latest std No actual bugs--other than one panic(nil)--but a few places where error nilness was unclear. Change-Id: Ia916ba30f46f29c1bcf928cc62280169b922463a Reviewed-on: https://go-review.googlesource.com/c/go/+/486675 Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Alan Donovan <adonovan@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Alan Donovan <adonovan@google.com>
2023-04-07encoding/xml: use reflect.Value.GrowDaniel Martí
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>
2023-04-04encoding/binary: add word size to the error message of the failed constraintConstantin Konstantinidis
Test added. Fixes #22860 Change-Id: I08304834a2b7b10b4ac729bf36761692eb4731da Reviewed-on: https://go-review.googlesource.com/c/go/+/113075 Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-04-04all: fix misuses of "a" vs "an"cui fliter
Fixes the misuse of "a" vs "an", according to English grammatical expectations and using https://www.a-or-an.com/ Change-Id: I53ac724070e3ff3d33c304483fe72c023c7cda47 Reviewed-on: https://go-review.googlesource.com/c/go/+/480536 Run-TryBot: shuang cui <imcusg@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2023-04-04encoding/gob: use reflect.Value.GrowDaniel Martí
Growing by one is a simpler, and often cheaper, operation compared to appending one (newly created) zero value. The method was introduced in Go 1.20. growSlice in dec_helpers.go is left alone, as it grows using the builtin append instead of reflect.Append. No noticeable performance difference on any of our benchmarks, as this code only runs for slices large enough to not fit in saferio.SliceCap, and none of our benchmarks use data that large. goos: linux goarch: amd64 pkg: encoding/gob cpu: AMD Ryzen 7 PRO 5850U with Radeon Graphics │ old │ new │ │ sec/op │ sec/op vs base │ DecodeBytesSlice-8 11.37µ ± 1% 11.46µ ± 4% ~ (p=0.315 n=10) DecodeInterfaceSlice-8 96.49µ ± 1% 95.75µ ± 1% ~ (p=0.436 n=10) geomean 33.12µ 33.12µ +0.01% │ old │ new │ │ B/op │ B/op vs base │ DecodeBytesSlice-8 22.39Ki ± 0% 22.39Ki ± 0% ~ (p=1.000 n=10) DecodeInterfaceSlice-8 80.25Ki ± 0% 80.25Ki ± 0% ~ (p=0.650 n=10) geomean 42.39Ki 42.39Ki +0.00% │ old │ new │ │ allocs/op │ allocs/op vs base │ DecodeBytesSlice-8 169.0 ± 0% 169.0 ± 0% ~ (p=1.000 n=10) ¹ DecodeInterfaceSlice-8 3.178k ± 0% 3.178k ± 0% ~ (p=1.000 n=10) ¹ geomean 732.9 732.9 +0.00% Change-Id: I468aebf4ae6f197a1fd35f6fee809ca591c1788f Reviewed-on: https://go-review.googlesource.com/c/go/+/481376 Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2023-04-04encoding/gob: report allocs in benchmarksDaniel Martí
I almost exclusively use these benchmarks with -benchtime already. Change-Id: I6539cbba6abbdb6b275502e122f4e16856d8b9e4 Reviewed-on: https://go-review.googlesource.com/c/go/+/481375 Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Rob Pike <r@golang.org>
2023-03-29encoding/gob: avoid pointers to fieldTypeDaniel Martí
fieldType is a struct with only a string and an integer, so its size will barely be three times that of a pointer. The indirection doesn't save us any memory or append/grow cost, but it does cause a significant amount of allocations at init time. goos: linux goarch: amd64 pkg: encoding/gob cpu: AMD Ryzen 7 PRO 5850U with Radeon Graphics │ old │ new │ │ sec/op │ sec/op vs base │ EndToEndPipe-16 730.9n ± 5% 741.6n ± 5% ~ (p=0.529 n=10) EncodingGob 173.7µ ± 0% 171.1µ ± 0% -1.46% (p=0.000 n=10) geomean 11.27µ 11.26µ -0.01% │ old │ new │ │ B/op │ B/op vs base │ EndToEndPipe-16 1.766Ki ± 0% 1.766Ki ± 0% ~ (p=1.000 n=10) ¹ EncodingGob 38.27Ki ± 0% 34.30Ki ± 0% -10.38% (p=0.000 n=10) geomean 8.221Ki 7.782Ki -5.33% ¹ all samples are equal │ old │ new │ │ allocs/op │ allocs/op vs base │ EndToEndPipe-16 2.000 ± 0% 2.000 ± 0% ~ (p=1.000 n=10) ¹ EncodingGob 642.0 ± 0% 615.0 ± 0% -4.21% (p=0.000 n=10) geomean 35.83 35.07 -2.13% ¹ all samples are equal Change-Id: I852a799834d2e9b7b915da74e871a4052d13892e Reviewed-on: https://go-review.googlesource.com/c/go/+/479400 Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Rob Pike <r@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>