1 Star 0 Fork 0

LonelyPale / goutils

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
slice.go 781 Bytes
一键复制 编辑 原始数据 按行查看 历史
LonelyPale 提交于 2021-02-01 10:57 . update slice
package goutils
func MergeSliceByte(ss ...[]byte) []byte {
switch len(ss) {
case 0:
return nil
case 1:
return ss[0]
default:
return mergeSliceCopy(ss...)
}
}
// copy 效率要比 append 大概高20%-30%
func mergeSliceCopy(ss ...[]byte) []byte {
length := 0
for _, s := range ss {
length += len(s)
}
slice := make([]byte, length)
index := 0
for _, s := range ss {
copy(slice[index:], s)
index += len(s)
}
return slice
}
func mergeSliceAppend(ss ...[]byte) []byte {
slice := make([]byte, 0)
for _, s := range ss {
slice = append(slice, s...)
}
return slice
}
func ReverseByte(arr []byte) []byte {
length := len(arr)
for i := 0; i < length/2; i++ {
idx := length - 1 - i
temp := arr[i]
arr[i] = arr[idx]
arr[idx] = temp
}
return arr
}
Go
1
https://gitee.com/lonelypalegit/goutils.git
git@gitee.com:lonelypalegit/goutils.git
lonelypalegit
goutils
goutils
master

搜索帮助