1
0
mirror of https://github.com/golang/go synced 2024-11-19 06:24:41 -07:00
go/src/strconv
Rob Pike c226f6432d strconv: pre-allocate in appendQuotedWith
The byte-at-a-time allocation done quoting strings in appendQuotedWith
grows the output incrementally, which is poor behavior for very large
strings. An easy fix is to make sure the buffer has enough room at
least for an unquoted string.

Add a benchmark with a megabyte of non-ASCII data.
	Before: 39 allocations.
	After: 7 allocations.

We could do better by doing a lot more work but this seems like a big
result for little effort.

Fixes #31472.

Change-Id: I852139e0a2bd13722c4dd329ded8ae1759abad5b
Reviewed-on: https://go-review.googlesource.com/c/go/+/172677
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-04-18 04:30:46 +00:00
..
testdata
atob_test.go
atob.go
atof_test.go strconv: accept underscores in ParseInt, ParseUint, ParseFloat 2019-02-12 14:48:24 +00:00
atof.go strconv: accept underscores in ParseInt, ParseUint, ParseFloat 2019-02-12 14:48:24 +00:00
atoi_test.go strconv: remove use of DeepEqual for testing errors 2019-02-27 18:23:19 +00:00
atoi.go strconv: add 0b, 0o integer prefixes in ParseInt, ParseUint 2019-02-12 14:48:26 +00:00
decimal_test.go
decimal.go
doc.go strconv: add missing package name into doc.go(godoc overview) 2018-12-30 18:30:11 +00:00
example_test.go strconv: add example for QuoteRuneToGraphic and QuoteToGraphic functions 2018-10-08 19:13:38 +00:00
export_test.go
extfloat.go strconv: simplify (*extFloat).Multiply using math/bits.Mul64 2019-03-04 22:25:21 +00:00
fp_test.go
ftoa_test.go strconv: format hex floats 2019-02-12 14:48:22 +00:00
ftoa.go strconv: format hex floats 2019-02-12 14:48:22 +00:00
internal_test.go
isprint.go
itoa_test.go
itoa.go strconv: make docs for Itoa and Atoi slightly higher level 2018-12-31 22:48:43 +00:00
makeisprint.go
quote_test.go
quote.go strconv: pre-allocate in appendQuotedWith 2019-04-18 04:30:46 +00:00
strconv_test.go strconv: pre-allocate in appendQuotedWith 2019-04-18 04:30:46 +00:00