1
0
mirror of https://github.com/json-iterator/go.git synced 2025-03-29 21:20:52 +02:00

fix #196 do not hard code 1 << 49

This commit is contained in:
Tao Wen 2017-11-15 23:15:31 +08:00
parent d394a135a1
commit 3c0e5762c4
2 changed files with 5 additions and 4 deletions

View File

@ -127,10 +127,10 @@ func growOne(slice *sliceHeader, sliceType reflect.Type, elementType reflect.Typ
newVal := reflect.MakeSlice(sliceType, newLen, newCap)
dst := unsafe.Pointer(newVal.Pointer())
// copy old array into new array
originalBytesCount := uintptr(slice.Len) * elementType.Size()
srcPtr := (*[1 << 49]byte)(slice.Data)
dstPtr := (*[1 << 49]byte)(dst)
copy(dstPtr[:originalBytesCount], srcPtr[:originalBytesCount])
originalBytesCount := slice.Len * int(elementType.Size())
srcSliceHeader := (unsafe.Pointer)(&sliceHeader{slice.Data, originalBytesCount, originalBytesCount})
dstSliceHeader := (unsafe.Pointer)(&sliceHeader{dst, originalBytesCount, originalBytesCount})
copy(*(*[]byte)(dstSliceHeader), *(*[]byte)(srcSliceHeader))
slice.Data = dst
slice.Len = newLen
slice.Cap = newCap

View File

@ -11,6 +11,7 @@ import (
)
func Test_write_empty_interface_via_placeholder(t *testing.T) {
fmt.Println(^uint(0) >> 1)
should := require.New(t)
m := map[uint32]interface{}{1:"hello"}
inf := reflect.ValueOf(m).MapIndex(reflect.ValueOf(uint32(1))).Interface()