From 6988a0571d5d37ea0f38ee3e4066533158f608bc Mon Sep 17 00:00:00 2001 From: Jeff Halter <868228+jhalter@users.noreply.github.com> Date: Sat, 24 Jul 2021 17:54:17 -0700 Subject: Initial squashed commit --- concat/slices.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 concat/slices.go (limited to 'concat') 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 +} + -- cgit