lang: types: We should use the platform-dependent int instead
This could be a 32 or 64 bit sized int depending on arch.
This commit is contained in:
@@ -23,13 +23,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// nextPowerOfTwo gets the lowest number higher than v that is a power of two.
|
// nextPowerOfTwo gets the lowest number higher than v that is a power of two.
|
||||||
func nextPowerOfTwo(v uint32) uint32 {
|
func nextPowerOfTwo(v uint) uint {
|
||||||
v--
|
v--
|
||||||
v |= v >> 1
|
v |= v >> 1
|
||||||
v |= v >> 2
|
v |= v >> 2
|
||||||
v |= v >> 4
|
v |= v >> 4
|
||||||
v |= v >> 8
|
v |= v >> 8
|
||||||
v |= v >> 16
|
v |= v >> 16
|
||||||
|
v |= v >> 32
|
||||||
v++
|
v++
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ package types
|
|||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
func TestNextPowerOfTwo(t *testing.T) {
|
func TestNextPowerOfTwo(t *testing.T) {
|
||||||
testCases := map[uint32]uint32{
|
testCases := map[uint]uint{
|
||||||
1: 1,
|
1: 1,
|
||||||
2: 2,
|
2: 2,
|
||||||
3: 4,
|
3: 4,
|
||||||
|
|||||||
@@ -333,7 +333,7 @@ func Into(v Value, rv reflect.Value) error {
|
|||||||
|
|
||||||
switch kind {
|
switch kind {
|
||||||
case reflect.Slice:
|
case reflect.Slice:
|
||||||
pow := nextPowerOfTwo(uint32(count))
|
pow := nextPowerOfTwo(uint(count))
|
||||||
nval := reflect.MakeSlice(rv.Type(), count, int(pow))
|
nval := reflect.MakeSlice(rv.Type(), count, int(pow))
|
||||||
rv.Set(nval)
|
rv.Set(nval)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user