aboutsummaryrefslogtreecommitdiff
path: root/concat/slices.go
blob: 88b9faed8afd2dce85494c5efe104f668e1cb724 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
}