aboutsummaryrefslogtreecommitdiff
path: root/src/strconv/atoc.go
AgeCommit message (Collapse)Author
2025-10-29strconv: move all but Quote to internal/strconvRuss Cox
This will let low-level things depend on the canonical routines, even for floating-point printing. Change-Id: I31207dc6584ad90d4e365dbe6eaf20f8662ed22d Reviewed-on: https://go-review.googlesource.com/c/go/+/716000 Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-05-05strconv: use stringslite.Cloneqiulaidongfeng
Change-Id: Ifa3c022ad5453301573593a3d05e7b1d42b931ff GitHub-Last-Rev: a7468b068b5c7bcaa573042cf9d5c2732c0385f1 GitHub-Pull-Request: golang/go#67167 Reviewed-on: https://go-review.googlesource.com/c/go/+/583215 Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Keith Randall <khr@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Commit-Queue: Ian Lance Taylor <iant@google.com> Auto-Submit: Keith Randall <khr@golang.org>
2024-04-04strconv: add available godoc linkcui fliter
Change-Id: Iad58155f29a101fb72768b170c0c2c9d76b6041a Reviewed-on: https://go-review.googlesource.com/c/go/+/539357 Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: qiu laidongfeng2 <2645477756@qq.com> Run-TryBot: shuang cui <imcusg@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2022-08-23strconv: optimize Parse for []byte argumentsJoe Tsai
When one has a []byte on hand, but desires to call the Parse functions, the conversion from []byte to string would allocate. var b []byte = ... v, err := strconv.ParseXXX(string(b), ...) This changes it such that the input string never escapes from any of the Parse functions. Together with the compiler optimization where the compiler stack allocates any string smaller than 32B this makes most valid inputs for strconv.ParseXXX(string(b), ...) not require an allocation for the input string. For example, the longest int64 or uint64 encoded in decimal is 20B. Also, the longest decimal formatting of a float64 in appendix B of RFC 8785 is 25B. Previously, this was not possible since the input leaked to the error, which causes the prover to give up and instead heap copy the []byte. We fix this by copying the input string in the error case. The advantage of this change is that you can now call strconv.ParseXXX with a []byte without allocations (most times) in the non-error case. The detriment is that the error-case now has an extra allocation. We should optimize for the non-error path, rather than the error path. The effects of this change is transitively seen through packages that must use strconv.ParseXXX on a []byte such as "encoding/json": name old time/op new time/op delta UnmarshalFloat64 186ns 157ns -15.89% (p=0.000 n=10+10) name old alloc/op new alloc/op delta UnmarshalFloat64 148B 144B -2.70% (p=0.000 n=10+10) name old allocs/op new allocs/op delta UnmarshalFloat64 2.00 1.00 -50.00% (p=0.000 n=10+10) In order for "encoding/json" to benefit, there needs to be a small change made to how "encoding/json" calls strconv.ParseXXX. That will be a future change. Credit goes to Jeff Wendling for a similar patch. Fixes #42429 Change-Id: I512d6927f965f82e95bd7ec14a28a587f23b7203 Reviewed-on: https://go-review.googlesource.com/c/go/+/345488 Reviewed-by: Martin Möhrmann <martin@golang.org> Run-TryBot: Joseph Tsai <joetsai@digital-static.net> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Auto-Submit: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: Robert Griesemer <gri@golang.org> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-11-03strconv: revert ParseFloat/ParseComplex error on incorrect bitSizeBen Hoyt
This is a partial revert of https://go-review.googlesource.com/c/go/+/248219 because we found that a non-trivial amount of code erroneously calls ParseFloat(s, 10) or even ParseFloat(s, 0) and expects it to work -- before that change was merged, ParseFloat accepted a bitSize of anything other than 32 or 64 to mean 64 (and ParseComplex was similar). So revert that behavior to avoid breaking people's code, and add tests for this. I may add a vet check to flag ParseFloat(s, not_32_or_64) in a later change. See #42297 for more details. Change-Id: I4bc0156bd74f67a39d5561b6e5fde3f2d20bd622 Reviewed-on: https://go-review.googlesource.com/c/go/+/267319 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-10-30strconv: fix incorrect bit size in ParseComplex; add testsBen Hoyt
In ParseComplex, the "size" passed to parseFloatPrefix should be 64 for complex128, not 128. It still works because of how parseFloatPrefix is forgiving about the size if it's not 32, but worth fixing anyway. Make ParseComplex and ParseFloat return a bit size error for anything other than 128 or 64 (for ParseComplex), or 64 or 32 (for ParseFloat). Add "InvalidBitSize" tests for these cases. Add tests for ParseComplex with bitSize==64: this is done in a similar way to how the ParseFloat 32-bit tests work, re-using the tests for the larger bit size. Add tests for FormatComplex -- there were none before. Fixes #40706 Change-Id: I16ddd546e5237207cc3b8c2181dd708eca42b04f Reviewed-on: https://go-review.googlesource.com/c/go/+/248219 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Trust: Minux Ma <minux@golang.org> Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2020-05-08strconv: add ParseComplex and FormatComplexpj
Adds two functions to deal with complex numbers: * FormatComplex * ParseComplex ParseComplex accepts complex numbers in this format: N+Ni Fixes #36771 Change-Id: Id184dc9e277e5fa01a714ad656a88255ead05085 GitHub-Last-Rev: 036a075d36363774a95f6000b7c4098896474744 GitHub-Pull-Request: golang/go#36815 Reviewed-on: https://go-review.googlesource.com/c/go/+/216617 Reviewed-by: Robert Griesemer <gri@golang.org>