We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 01fb0b7 commit 0fa6402Copy full SHA for 0fa6402
append.go
@@ -0,0 +1,20 @@
1
+package bytespool
2
+
3
+// Append appends the specified bytes to the buf byte slice.
4
+// The buf byte slice passed to Append MUST NOT be used after
5
+// Append is called: only the byte slice returned should be
6
+// used.
7
+func Append(buf []byte, v ...byte) []byte {
8
+ if len(v) <= cap(buf)-len(buf) {
9
+ return append(buf, v...)
10
+ }
11
+ return appendSlow(buf, v...)
12
+}
13
14
+func appendSlow(buf []byte, v ...byte) []byte {
15
+ pbuf := GetBytesSlicePtr((len(v)+len(buf))*2)
16
+ nbuf := append(append((*pbuf)[:0], buf...), v...)
17
+ *pbuf = buf
18
+ PutBytesSlicePtr(pbuf)
19
+ return nbuf
20
0 commit comments