1
0
mirror of https://github.com/golang/go synced 2024-11-07 12:36:27 -07:00
go/api/next
Joe Tsai e671fe0c3e bytes: add Buffer.Available and Buffer.AvailableBuffer
This adds a new Buffer.AvailableBuffer method that returns
an empty buffer with a possibly non-empty capacity for use
with append-like APIs.

The typical usage pattern is something like:

	b := bb.AvailableBuffer()
	b = appendValue(b, v)
	bb.Write(b)

It allows logic combining append-like APIs with Buffer
to avoid needing to allocate and manage buffers themselves and
allows the append-like APIs to directly write into the Buffer.

The Buffer.Write method uses the builtin copy function,
which avoids copying bytes if the source and destination are identical.
Thus, Buffer.Write is a constant-time call for this pattern.

Performance:

	BenchmarkBufferAppendNoCopy  2.909 ns/op  5766942167.24 MB/s

This benchmark should only be testing the cost of bookkeeping
and never the copying of the input slice.
Thus, the MB/s should be orders of magnitude faster than RAM.

Fixes #53685

Change-Id: I0b41e54361339df309db8d03527689b123f99085
Reviewed-on: https://go-review.googlesource.com/c/go/+/474635
Run-TryBot: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-03-13 17:03:14 +00:00
..
25448.txt runtime: replace panic(nil) with panic(new(runtime.PanicNilError)) 2023-01-19 22:21:50 +00:00
41198.txt errors: add ErrUnsupported 2023-03-11 05:07:02 +00:00
46259.txt syscall: add jail support to ForkExec on FreeBSD 2023-02-22 20:38:48 +00:00
53685.txt bytes: add Buffer.Available and Buffer.AvailableBuffer 2023-03-13 17:03:14 +00:00
54386.txt bytes, strings: add ContainsFunc 2023-01-24 22:06:45 +00:00
55002.txt reflect,runtime: add Value.Clear 2023-01-30 16:00:58 +00:00
55079.txt all: upgrade Unicode from 13.0.0 to 15.0.0 2023-02-06 04:29:53 +00:00
56491.txt math: add Compare and Compare32 2023-02-15 21:56:30 +00:00
56661.txt context: add APIs for setting a cancelation cause when deadline or timer expires 2023-01-20 21:41:01 +00:00
56887.txt debug/elf: add DT_FLAGS_1 constants 2023-02-03 04:37:17 +00:00
56892.txt debug/elf: retrieve values for dynamic section tags 2023-03-07 18:26:40 +00:00
56984.txt math/big: add Int.Float64 conversion 2023-02-02 19:39:34 +00:00
56986.txt cmd/go, go/build: parse directives in file headers 2023-02-23 10:10:21 +00:00
57237.txt encoding/binary: add var NativeEndian 2023-01-27 18:17:20 +00:00
57433.txt slices: new package 2023-02-13 21:00:42 +00:00
57436.txt maps: new package 2023-02-03 18:22:53 +00:00
57708.txt go/token: add (*File).Lines method 2023-02-02 16:40:29 +00:00
57786.txt net/http: support full-duplex HTTP/1 responses 2023-03-07 22:52:18 +00:00