-
-
Save l1905/424f15d629ee0dcdb5c4727c0c83559a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func AppendByte(slice []byte, data ...byte) []byte { | |
m := len(slice) | |
n := m + len(data) | |
if n > cap(slice) { // if necessary, reallocate | |
// allocate double what's needed, for future growth. | |
newSlice := make([]byte, (n+1)*2) | |
copy(newSlice, slice) | |
slice = newSlice | |
} | |
slice = slice[0:n] | |
copy(slice[m:n], data) | |
return slice | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment