Skip to content

Instantly share code, notes, and snippets.

@leolee192
Created December 22, 2019 15:37
Show Gist options
  • Save leolee192/4a9991abb64d978564822e16cba36b03 to your computer and use it in GitHub Desktop.
Save leolee192/4a9991abb64d978564822e16cba36b03 to your computer and use it in GitHub Desktop.
concatCopyPreAllocate.go
func concatCopyPreAllocate(slices [][]byte) []byte {
var totalLen int
for _, s := range slices {
totalLen += len(s)
}
tmp := make([]byte, totalLen)
var i int
for _, s := range slices {
i += copy(tmp[i:], s)
}
return tmp
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment