summaryrefslogtreecommitdiff
path: root/src/bytes/buffer.go
Commit message (Collapse)AuthorAgeFilesLines
* bytes: correct tense in commentIan Lance Taylor2021-03-151-1/+1
| | | | | | | | | Undo incorrect change accidentally made in CL 299109. Change-Id: Iba29827d0fbd3637c311cebc50c2f4ea437fc582 Reviewed-on: https://go-review.googlesource.com/c/go/+/301830 Trust: Ian Lance Taylor <iant@golang.org> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
* all: remove duplicate wordsJohn Bampton2021-03-131-1/+1
| | | | | | | | | | | Change-Id: Ib0469232a2b69a869e58d5d24990ad74ac96ea56 GitHub-Last-Rev: eb38e049ee1e773392ff3747e1eb2af20dd50dcd GitHub-Pull-Request: golang/go#44805 Reviewed-on: https://go-review.googlesource.com/c/go/+/299109 Trust: Emmanuel Odeke <emmanuel@orijtech.com> Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
* bufio, bytes, strings: handle negative runes in WriteRuneDavid Benjamin2021-02-241-1/+2
| | | | | | | | | | | | Updates #43254 Change-Id: I7d4bf3b99cc36ca2156af5bb01a1c595419d1d3c Reviewed-on: https://go-review.googlesource.com/c/go/+/280492 Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Reviewed-by: Rob Pike <r@golang.org> Trust: Emmanuel Odeke <emmanuel@orijtech.com> Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com> TryBot-Result: Go Bot <gobot@golang.org>
* bytes: remove obsolete commentMaxim Eryomenko2019-05-281-3/+0
| | | | | | | | Change-Id: Iec4348eb674c8c64497c82e5d7cd656736cfcebd GitHub-Last-Rev: 462c323960be0ca1c126c051ab97f72949bdc2b6 GitHub-Pull-Request: golang/go#32225 Reviewed-on: https://go-review.googlesource.com/c/go/+/178797 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* bytes: hoist error creation out of functionMarcel van Lohuizen2019-02-261-1/+3
| | | | | | | | | | | | | | generating frame information in errors will cause this function to no longer be inlined. Updates #29934. Change-Id: I1d7bc11707f1872d7315f627bfb9a12afa41e358 Reviewed-on: https://go-review.googlesource.com/c/161760 Run-TryBot: Marcel van Lohuizen <mpvl@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* all: use "reports whether" consistently instead of "returns whether"Tobias Klauser2018-12-021-1/+1
| | | | | | | | | | | | | | | | | | | | | Follow-up for CL 147037 and after Brad noticed the "returns whether" pattern during the review of CL 150621. Go documentation style for boolean funcs is to say: // Foo reports whether ... func Foo() bool (rather than "returns whether") Created with: $ perl -i -npe 's/returns whether/reports whether/' $(git grep -l "returns whether" | grep -v vendor) Change-Id: I15fe9ff99180ad97750cd05a10eceafdb12dc0b4 Reviewed-on: https://go-review.googlesource.com/c/150918 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* bytes: remove bootstrap array from BufferIskander Sharipov2018-09-061-7/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Rationale: small buffer optimization does not work and it has made things slower since 2014. Until we can make it work, we should prefer simpler code that also turns out to be more efficient. With this change, it's possible to use NewBuffer(make([]byte, 0, bootstrapSize)) to get the desired stack-allocated initial buffer since escape analysis can prove the created slice to be non-escaping. New implementation key points: - Zero value bytes.Buffer performs better than before - You can have a truly stack-allocated buffer, and it's not even limited to 64 bytes - The unsafe.Sizeof(bytes.Buffer{}) is reduced significantly - Empty writes don't cause allocations Buffer benchmarks from bytes package: name old time/op new time/op delta ReadString-8 9.20µs ± 1% 9.22µs ± 1% ~ (p=0.148 n=10+10) WriteByte-8 28.1µs ± 0% 26.2µs ± 0% -6.78% (p=0.000 n=10+10) WriteRune-8 64.9µs ± 0% 65.0µs ± 0% +0.16% (p=0.000 n=10+10) BufferNotEmptyWriteRead-8 469µs ± 0% 461µs ± 0% -1.76% (p=0.000 n=9+10) BufferFullSmallReads-8 108µs ± 0% 108µs ± 0% -0.21% (p=0.000 n=10+10) name old speed new speed delta ReadString-8 3.56GB/s ± 1% 3.55GB/s ± 1% ~ (p=0.165 n=10+10) WriteByte-8 146MB/s ± 0% 156MB/s ± 0% +7.26% (p=0.000 n=9+10) WriteRune-8 189MB/s ± 0% 189MB/s ± 0% -0.16% (p=0.000 n=10+10) name old alloc/op new alloc/op delta ReadString-8 32.8kB ± 0% 32.8kB ± 0% ~ (all equal) WriteByte-8 0.00B 0.00B ~ (all equal) WriteRune-8 0.00B 0.00B ~ (all equal) BufferNotEmptyWriteRead-8 4.72kB ± 0% 4.67kB ± 0% -1.02% (p=0.000 n=10+10) BufferFullSmallReads-8 3.44kB ± 0% 3.33kB ± 0% -3.26% (p=0.000 n=10+10) name old allocs/op new allocs/op delta ReadString-8 1.00 ± 0% 1.00 ± 0% ~ (all equal) WriteByte-8 0.00 0.00 ~ (all equal) WriteRune-8 0.00 0.00 ~ (all equal) BufferNotEmptyWriteRead-8 3.00 ± 0% 3.00 ± 0% ~ (all equal) BufferFullSmallReads-8 3.00 ± 0% 2.00 ± 0% -33.33% (p=0.000 n=10+10) The most notable thing in go1 benchmarks is reduced allocs in HTTPClientServer (-1 alloc): HTTPClientServer-8 64.0 ± 0% 63.0 ± 0% -1.56% (p=0.000 n=10+10) For more explanations and benchmarks see the referenced issue. Updates #7921 Change-Id: Ica0bf85e1b70fb4f5dc4f6a61045e2cf4ef72aa3 Reviewed-on: https://go-review.googlesource.com/133715 Reviewed-by: Martin Möhrmann <moehrmann@google.com> Reviewed-by: Robert Griesemer <gri@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* bytes: note that NewBuffer's initial size can changeAlberto Donizetti2018-08-291-3/+3
| | | | | | | | | | | | | | | | | | | | | bytes.NewBuffer's documentation says it can be used to set the initial size of the buffer. The current wording is: > It can also be used to size the internal buffer for writing. This may led users to believe that the buffer (its backing array) is fixed in size and won't grow, which isn't true (subsequent Write calls will expand the backing array as needed). Change the doc to make it clearer that NewBuffer just sets the initial size of the buffer. Fixes #27242 Change-Id: I2a8cb5bee02ca2c1657ef59e2cf1434c7a9bd397 Reviewed-on: https://go-review.googlesource.com/132035 Reviewed-by: Dominik Honnef <dominik@honnef.co> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* bytes: re-slice buffer to its previous length after call to grow()Dave Russell2018-05-291-0/+1
| | | | | | | | | | | | | | Fixes #25435 The added test fails without the re-slice and passes with it. Change-Id: I5ebc2a737285eb116ecc5938d8bf49050652830f GitHub-Last-Rev: 454ddad7df8d56a1d0e05a999ed8277c5516ce01 GitHub-Pull-Request: golang/go#25436 Reviewed-on: https://go-review.googlesource.com/113495 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* bytes: mention strings.Builder in Buffer.String docsBrad Fitzpatrick2017-11-301-0/+2
| | | | | | | | Fixes #22778 Change-Id: I37f7a59c15828aa720fe787fff42fb3ef17729c7 Reviewed-on: https://go-review.googlesource.com/80815 Reviewed-by: Ian Lance Taylor <iant@golang.org>
* bytes: don't use an iota for the readOp constantsDaniel Martí2017-11-191-6/+8
| | | | | | | | | | | As per the comments in golang.org/cl/78617. Also leaving a comment here, to make sure noone else thinks to re-introduce the iota like I did. Change-Id: I2a2275998b81896eaa0e9d5ee0197661ebe84acf Reviewed-on: https://go-review.googlesource.com/78676 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* bytes: make all readOp constants actually typedDaniel Martí2017-11-181-6/+6
| | | | | | | | | | | | | | | This is a regression introduced in golang.org/cl/28817. That change got rid of the iota, which meant that the type was no longer applied to all the constant names. Re-add the iota starting at -1, simplifying the code and adding the types once more. Change-Id: I38bd0e04f8d298196bccd33651e29f5011401a8d Reviewed-on: https://go-review.googlesource.com/78617 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* bytes: panic in ReadFrom with more information with negative Read countsAfanasev Stanislav2017-10-061-0/+5
| | | | | | | | | | | | This is only to aid in human debugging, and for that reason we maintain a panic, and not return an error. Fixes #22097 Change-Id: If72e4d1e47ec9125ca7bc97d5fe4cedb7f76ae72 Reviewed-on: https://go-review.googlesource.com/67970 Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com> Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
* bytes: removed unnecessary slicing on copyGabriel Aszalos2017-09-181-1/+1
| | | | | | | | Change-Id: Ia42e3479c852a88968947411de8b32e5bcda5ae3 Reviewed-on: https://go-review.googlesource.com/64371 Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com> Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
* bytes: clean-up of buffer.goMarvin Stenger2017-08-181-45/+23
| | | | | | | | | | | | | | | Clean-up changes in no particular order: - use uint8 instead of int for readOp - remove duplicated code in ReadFrom() - introduce (*Buffer).empty() - remove naked returns Change-Id: Ie6e673c20c398f980f8be0448969a36ad4778804 Reviewed-on: https://go-review.googlesource.com/42816 Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org>
* bytes: avoid overflow in (*Buffer).Grow and ReadFromBryan C. Mills2017-08-161-4/+13
| | | | | | | | fixes #21481 Change-Id: I26717876a1c0ee25a86c81159c6b3c59563dfec6 Reviewed-on: https://go-review.googlesource.com/56230 Reviewed-by: Ian Lance Taylor <iant@golang.org>
* bytes: note that NewBuffer take ownership of its argumentAlberto Donizetti2017-06-021-4/+6
| | | | | | | | Fixes #19383 Change-Id: Ic84517053ced7794006f6fc65e6f249e97d6cf35 Reviewed-on: https://go-review.googlesource.com/44691 Reviewed-by: Ian Lance Taylor <iant@golang.org>
* bytes: optimize Buffer's Write, WriteString, WriteByte, and WriteRuneMarvin Stenger2017-05-071-23/+50
| | | | | | | | | | | | | | | | | | | | | | | | | | In the common case, the grow method only needs to reslice the internal buffer. Making another function call to grow can be expensive when Write is called very often with small pieces of data (like a byte or rune). Thus, we add a tryGrowByReslice method that is inlineable so that we can avoid an extra call in most cases. name old time/op new time/op delta WriteByte-4 35.5µs ± 0% 17.4µs ± 1% -51.03% (p=0.000 n=19+20) WriteRune-4 55.7µs ± 1% 38.7µs ± 1% -30.56% (p=0.000 n=18+19) BufferNotEmptyWriteRead-4 304µs ± 5% 283µs ± 3% -6.86% (p=0.000 n=19+17) BufferFullSmallReads-4 87.0µs ± 5% 66.8µs ± 2% -23.26% (p=0.000 n=17+17) name old speed new speed delta WriteByte-4 115MB/s ± 0% 235MB/s ± 1% +104.19% (p=0.000 n=19+20) WriteRune-4 221MB/s ± 1% 318MB/s ± 1% +44.01% (p=0.000 n=18+19) Fixes #17857 Change-Id: I08dfb10a1c7e001817729dbfcc951bda12fe8814 Reviewed-on: https://go-review.googlesource.com/42813 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* bytes: clarify documentation for UnreadByte/RuneRobert Griesemer2017-04-281-6/+7
| | | | | | | | Fixes #19522. Change-Id: Ib3cf0336e0bf91580d533704ec1a9d45eb0bf62d Reviewed-on: https://go-review.googlesource.com/42020 Reviewed-by: Rob Pike <r@golang.org>
* bytes: make bytes.Buffer cache-friendlyCarlo Alberto Ferraris2017-02-281-16/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | During benchmark of an internal tool we found out that (*Buffer).Reset() was surprisingly showing up in CPU profiles. This CL contains two related changes aimed at speeding up Reset(): 1. Create a fast path for Truncate(0) by moving the logic to Reset() (this makes Reset() a simple leaf func that gets inlined since it gets compiled to 3 MOVx instructions). Accordingly change calls in the rest of the Buffer methods to call Reset() instead of Truncate(0). 2. Reorder the fields in the Buffer struct so that frequently accessed fields are packed together (buf, off, lastRead). This also make them likely to be in the same cacheline. Ideally it would be advisable to have Buffer{} cacheline-aligned, but I couldn't find a way to do this without changing the size of the bootstrap array (but this will cause some regressions, because it will make duffcopy show up in CPU profiles where it wasn't showing up before). go1 benchmarks are not really affected, but some other benchmarks that exercise Buffer more show improvements: name old time/op new time/op delta BinaryTree17-4 2.46s ± 9% 2.43s ± 3% ~ (p=0.982 n=14+14) Fannkuch11-4 2.98s ± 1% 2.90s ± 1% -2.58% (p=0.000 n=15+14) FmtFprintfEmpty-4 45.2ns ± 1% 45.2ns ± 1% ~ (p=0.494 n=14+15) FmtFprintfString-4 76.8ns ± 1% 83.1ns ± 2% +8.23% (p=0.000 n=10+15) FmtFprintfInt-4 78.0ns ± 2% 74.6ns ± 1% -4.46% (p=0.000 n=15+15) FmtFprintfIntInt-4 113ns ± 1% 109ns ± 2% -2.91% (p=0.000 n=13+15) FmtFprintfPrefixedInt-4 152ns ± 2% 143ns ± 2% -6.04% (p=0.000 n=15+14) FmtFprintfFloat-4 224ns ± 1% 222ns ± 2% -1.08% (p=0.001 n=15+14) FmtManyArgs-4 464ns ± 2% 463ns ± 2% ~ (p=0.303 n=14+15) GobDecode-4 6.25ms ± 2% 6.32ms ± 3% +1.20% (p=0.002 n=14+14) GobEncode-4 5.41ms ± 2% 5.41ms ± 2% ~ (p=0.967 n=15+15) Gzip-4 215ms ± 2% 218ms ± 2% +1.35% (p=0.002 n=15+15) Gunzip-4 34.3ms ± 2% 34.2ms ± 2% ~ (p=0.539 n=15+15) HTTPClientServer-4 76.4µs ± 2% 75.4µs ± 1% -1.31% (p=0.000 n=15+15) JSONEncode-4 14.7ms ± 2% 14.6ms ± 3% ~ (p=0.094 n=14+14) JSONDecode-4 48.0ms ± 1% 48.5ms ± 1% +0.92% (p=0.001 n=14+12) Mandelbrot200-4 4.04ms ± 2% 4.06ms ± 1% ~ (p=0.108 n=15+13) GoParse-4 2.99ms ± 2% 3.00ms ± 1% ~ (p=0.130 n=15+13) RegexpMatchEasy0_32-4 78.3ns ± 1% 79.5ns ± 1% +1.51% (p=0.000 n=15+14) RegexpMatchEasy0_1K-4 185ns ± 1% 186ns ± 1% +0.76% (p=0.005 n=15+15) RegexpMatchEasy1_32-4 79.0ns ± 2% 76.7ns ± 1% -2.87% (p=0.000 n=14+15) name old speed new speed delta GobDecode-4 123MB/s ± 2% 121MB/s ± 3% -1.18% (p=0.002 n=14+14) GobEncode-4 142MB/s ± 2% 142MB/s ± 1% ~ (p=0.959 n=15+15) Gzip-4 90.3MB/s ± 2% 89.1MB/s ± 2% -1.34% (p=0.002 n=15+15) Gunzip-4 565MB/s ± 2% 567MB/s ± 2% ~ (p=0.539 n=15+15) JSONEncode-4 132MB/s ± 2% 133MB/s ± 3% ~ (p=0.091 n=14+14) JSONDecode-4 40.4MB/s ± 1% 40.0MB/s ± 1% -0.92% (p=0.001 n=14+12) GoParse-4 19.4MB/s ± 2% 19.3MB/s ± 1% ~ (p=0.121 n=15+13) RegexpMatchEasy0_32-4 409MB/s ± 1% 403MB/s ± 1% -1.47% (p=0.000 n=15+14) RegexpMatchEasy0_1K-4 5.53GB/s ± 1% 5.49GB/s ± 1% -0.86% (p=0.002 n=15+15) RegexpMatchEasy1_32-4 405MB/s ± 2% 417MB/s ± 1% +2.94% (p=0.000 n=14+15) name old time/op new time/op delta PoolsSingle1K-4 34.9ns ± 2% 30.4ns ± 4% -12.80% (p=0.000 n=15+15) PoolsSingle64K-4 36.9ns ± 1% 34.4ns ± 4% -6.72% (p=0.000 n=14+15) PoolsRandomSmall-4 34.8ns ± 3% 29.5ns ± 1% -15.19% (p=0.000 n=15+14) PoolsRandomLarge-4 38.6ns ± 1% 34.3ns ± 3% -11.17% (p=0.000 n=14+15) PoolSingle1K-4 26.1ns ± 1% 21.2ns ± 2% -18.59% (p=0.000 n=15+14) PoolSingle64K-4 26.7ns ± 2% 21.5ns ± 2% -19.72% (p=0.000 n=15+15) MakeSingle1K-4 24.2ns ± 2% 24.3ns ± 3% ~ (p=0.132 n=13+15) MakeSingle64K-4 6.76µs ± 1% 6.96µs ± 5% +2.94% (p=0.002 n=13+13) MakeRandomSmall-4 531ns ± 4% 538ns ± 5% ~ (p=0.066 n=14+15) MakeRandomLarge-4 152µs ± 0% 152µs ± 1% -0.31% (p=0.001 n=14+13) Change-Id: I86d7d9d2cac65335baf62214fbb35ba0fd8f9528 Reviewed-on: https://go-review.googlesource.com/37416 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* all: fix misspellingsshawnps2017-01-071-1/+1
| | | | | | | | | Change-Id: I429637ca91f7db4144f17621de851a548dc1ce76 Reviewed-on: https://go-review.googlesource.com/34923 Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* bytes: encode size of rune read by ReadRune into lastRead to speed up UnreadRuneMartin Möhrmann2016-10-171-12/+16
| | | | | | | | | | | | | | | | In ReadRune store the size of the rune that was read into lastRead to avoid the need to call DecodeRuneLast in UnreadRune. fmt: name old time/op new time/op delta ScanInts-4 481µs ± 4% 458µs ± 3% -4.64% (p=0.000 n=20+20) Change-Id: I500848e663a975f426402a4b3d27a541e5cac06c Reviewed-on: https://go-review.googlesource.com/28817 Reviewed-by: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Run-TryBot: Martin Möhrmann <martisch@uos.de> TryBot-Result: Gobot Gobot <gobot@golang.org>
* bytes: improve WriteRune performanceMartin Möhrmann2016-09-081-7/+8
| | | | | | | | | | | | | | | | | Remove the runeBytes buffer and write the utf8 encoding directly to the internal buf byte slice. name old time/op new time/op delta WriteRune-4 80.5µs ± 2% 57.1µs ± 2% -29.06% (p=0.000 n=20+20) name old speed new speed delta WriteRune-4 153MB/s ± 2% 215MB/s ± 2% +40.96% (p=0.000 n=20+20) Change-Id: Ic15f6e2d6e56a3d15c74f56159e2eae020ba73ba Reviewed-on: https://go-review.googlesource.com/28816 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* bytes: correct comment about usage of bytes.Buffer by PrintfMartin Möhrmann2016-03-101-1/+1
| | | | | | | | | The fmt package does not use bytes.Buffer anymore as an internal buffer. Change-Id: I34c7a52506290ccbcb10ea2e85dea49a0a8b8203 Reviewed-on: https://go-review.googlesource.com/20511 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* all: single space after period.Brad Fitzpatrick2016-03-021-5/+5
| | | | | | | | | | | | | | | | | | | | The tree's pretty inconsistent about single space vs double space after a period in documentation. Make it consistently a single space, per earlier decisions. This means contributors won't be confused by misleading precedence. This CL doesn't use go/doc to parse. It only addresses // comments. It was generated with: $ perl -i -npe 's,^(\s*// .+[a-z]\.) +([A-Z]),$1 $2,' $(git grep -l -E '^\s*//(.+\.) +([A-Z])') $ go test go/doc -update Change-Id: Iccdb99c37c797ef1f804a94b22ba5ee4b500c4f7 Reviewed-on: https://go-review.googlesource.com/20022 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Dave Day <djd@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* all: remove public named return values when uselessBrad Fitzpatrick2016-02-291-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Named returned values should only be used on public funcs and methods when it contributes to the documentation. Named return values should not be used if they're only saving the programmer a few lines of code inside the body of the function, especially if that means there's stutter in the documentation or it was only there so the programmer could use a naked return statement. (Naked returns should not be used except in very small functions) This change is a manual audit & cleanup of public func signatures. Signatures were not changed if: * the func was private (wouldn't be in public godoc) * the documentation referenced it * the named return value was an interesting name. (i.e. it wasn't simply stutter, repeating the name of the type) There should be no changes in behavior. (At least: none intended) Change-Id: I3472ef49619678fe786e5e0994bdf2d9de76d109 Reviewed-on: https://go-review.googlesource.com/20024 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Andrew Gerrand <adg@golang.org>
* bytes: make Buffer comment more accurateJosh Bleecher Snyder2016-02-211-1/+1
| | | | | | Change-Id: Ief22b3dbba9616dd40bf3ea8e2633d3c5e7d1886 Reviewed-on: https://go-review.googlesource.com/19761 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* bytes: document that buffer is reused in Truncate and ResetJoe Tsai2015-12-181-7/+10
| | | | | | | | Fixes #13671 Change-Id: Ic752de6a3030ff25474717505fa05895054217e7 Reviewed-on: https://go-review.googlesource.com/18029 Reviewed-by: Russ Cox <rsc@golang.org>
* Revert "bytes: document that Buffer values must not be copied"Alan Donovan2015-07-231-1/+0
| | | | | | | | This reverts commit b1177d390cf0c3733836e5941f77b828e21c8a09. Change-Id: Iffbd63d5993633143a81572b223e3c5dd2353206 Reviewed-on: https://go-review.googlesource.com/12581 Reviewed-by: Alan Donovan <adonovan@google.com>
* bytes: document that Buffer values must not be copiedAlan Donovan2015-07-231-0/+1
| | | | | | Change-Id: If0821a2af987b78ed8024b40d9ffa68032518b22 Reviewed-on: https://go-review.googlesource.com/12572 Reviewed-by: Robert Griesemer <gri@golang.org>
* bytes: fix commentJosh Bleecher Snyder2015-04-041-1/+1
| | | | | | | | The the has been deleted. Change-Id: I4290105435d4f1fd10c7014f913a3147ddeb3c2b Reviewed-on: https://go-review.googlesource.com/8469 Reviewed-by: Ian Lance Taylor <iant@golang.org>
* bytes: export Cap method for bufferCristian Staretu2015-04-031-0/+4
| | | | | | | | | | | | | | | | | | | | | Obtaining the actual size of the underlying storage of the buffer can be very useful in various scenarios. Long running programs which write and read large amounts of data to buffers might have to recycle buffers in order to avoid holding onto potentially huge buffers. For example, a piece of code which buffers a lot of data in a buffer might need to release the big buffer and start again with a smaller buffer after it finished processing the huge amount of data. In cases where pools of bytes.Buffer are used, being able to check the size of the allocated data can be very useful. Instead of forking bytes.Buffer or writing new code, we can export the Cap() method. Change-Id: I79d4f0a3cff53b9419d82c8122964761e9e38566 Reviewed-on: https://go-review.googlesource.com/8342 Reviewed-by: Rob Pike <r@golang.org>
* build: move package sources from src/pkg to srcRuss Cox2014-09-081-0/+412
Preparation was in CL 134570043. This CL contains only the effect of 'hg mv src/pkg/* src'. For more about the move, see golang.org/s/go14nopkg.