1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-12 08:42:29 +08:00

feat: remove ConvertSlice func

This commit is contained in:
dudaodong
2022-01-19 20:41:46 +08:00
parent 2ab898741d
commit 28317a1683
4 changed files with 1 additions and 36 deletions

View File

@@ -12,7 +12,6 @@ import (
"reflect"
"sort"
"strings"
"unsafe"
)
// Contain check if the value is in the iterable type or not
@@ -427,26 +426,6 @@ func IntSlice(slice interface{}) []int {
return out
}
// ConvertSlice convert original slice to new data type element of slice.
func ConvertSlice(originalSlice interface{}, newSliceType reflect.Type) interface{} {
sv := sliceValue(originalSlice)
if newSliceType.Kind() != reflect.Slice {
panic(fmt.Sprintf("Invalid newSliceType(non-slice type of type %T)", newSliceType))
}
newSlice := reflect.New(newSliceType)
hdr := (*reflect.SliceHeader)(unsafe.Pointer(newSlice.Pointer()))
var newElemSize = int(sv.Type().Elem().Size()) / int(newSliceType.Elem().Size())
hdr.Cap = sv.Cap() * newElemSize
hdr.Len = sv.Len() * newElemSize
hdr.Data = sv.Pointer()
return newSlice.Elem().Interface()
}
// DeleteByIndex delete the element of slice from start index to end index - 1.
// Delete i: s = append(s[:i], s[i+1:]...)
// Delete i to j: s = append(s[:i], s[j:]...)