diff options
| author | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2021-07-24 17:54:17 -0700 |
|---|---|---|
| committer | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2021-07-24 17:54:17 -0700 |
| commit | 6988a0571d5d37ea0f38ee3e4066533158f608bc (patch) | |
| tree | 172010de54ea7e732d7daa836db659021dc8a933 /concat | |
Initial squashed commit
Diffstat (limited to 'concat')
| -rw-r--r-- | concat/slices.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/concat/slices.go b/concat/slices.go new file mode 100644 index 0000000..daf8aae --- /dev/null +++ b/concat/slices.go @@ -0,0 +1,18 @@ +package concat + +// Slices is a utility function to make appending multiple slices less painful and more efficient +// Source: https://stackoverflow.com/questions/37884361/concat-multiple-slices-in-golang +func Slices(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 +} + |