Tao Wen 7 anni fa
parent
commit
5db70aa4d6

+ 1 - 1
go_below_17.go

@@ -6,4 +6,4 @@ import "unsafe"
 
 func resolveTypeOff(rtype unsafe.Pointer, off int32) unsafe.Pointer {
 	return nil
-}
+}

+ 3 - 3
reflect2.go

@@ -1,9 +1,9 @@
 package reflect2
 
 import (
+	"github.com/modern-go/concurrent"
 	"reflect"
 	"unsafe"
-	"github.com/modern-go/concurrent"
 )
 
 type Type interface {
@@ -136,7 +136,7 @@ type frozenConfig struct {
 func (cfg Config) Froze() *frozenConfig {
 	return &frozenConfig{
 		useSafeImplementation: cfg.UseSafeImplementation,
-		cache:                 concurrent.NewMap(),
+		cache: concurrent.NewMap(),
 	}
 }
 
@@ -279,4 +279,4 @@ func likePtrType(typ reflect.Type) bool {
 func NoEscape(p unsafe.Pointer) unsafe.Pointer {
 	x := uintptr(p)
 	return unsafe.Pointer(x ^ 0)
-}
+}

+ 16 - 16
reflect2_kind.go

@@ -11,20 +11,20 @@ func DefaultTypeOfKind(kind reflect.Kind) Type {
 }
 
 var kindTypes = map[reflect.Kind]Type{
-	reflect.Bool: TypeOf(true),
-	reflect.Uint8: TypeOf(uint8(0)),
-	reflect.Int8: TypeOf(int8(0)),
-	reflect.Uint16: TypeOf(uint16(0)),
-	reflect.Int16: TypeOf(int16(0)),
-	reflect.Uint32: TypeOf(uint32(0)),
-	reflect.Int32: TypeOf(int32(0)),
-	reflect.Uint64: TypeOf(uint64(0)),
-	reflect.Int64: TypeOf(int64(0)),
-	reflect.Uint: TypeOf(uint(0)),
-	reflect.Int: TypeOf(int(0)),
-	reflect.Float32: TypeOf(float32(0)),
-	reflect.Float64: TypeOf(float64(0)),
-	reflect.Uintptr: TypeOf(uintptr(0)),
-	reflect.String: TypeOf(""),
+	reflect.Bool:          TypeOf(true),
+	reflect.Uint8:         TypeOf(uint8(0)),
+	reflect.Int8:          TypeOf(int8(0)),
+	reflect.Uint16:        TypeOf(uint16(0)),
+	reflect.Int16:         TypeOf(int16(0)),
+	reflect.Uint32:        TypeOf(uint32(0)),
+	reflect.Int32:         TypeOf(int32(0)),
+	reflect.Uint64:        TypeOf(uint64(0)),
+	reflect.Int64:         TypeOf(int64(0)),
+	reflect.Uint:          TypeOf(uint(0)),
+	reflect.Int:           TypeOf(int(0)),
+	reflect.Float32:       TypeOf(float32(0)),
+	reflect.Float64:       TypeOf(float64(0)),
+	reflect.Uintptr:       TypeOf(uintptr(0)),
+	reflect.String:        TypeOf(""),
 	reflect.UnsafePointer: TypeOf(unsafe.Pointer(nil)),
-}
+}

+ 1 - 1
safe_field.go

@@ -55,4 +55,4 @@ func (field *safeField) Get(obj interface{}) interface{} {
 
 func (field *safeField) UnsafeGet(obj unsafe.Pointer) unsafe.Pointer {
 	panic("does not support unsafe operation")
-}
+}

+ 3 - 3
safe_map.go

@@ -76,8 +76,8 @@ func (type2 *safeMapType) UnsafeIterate(obj unsafe.Pointer) MapIterator {
 }
 
 type safeMapIterator struct {
-	i int
-	m reflect.Value
+	i    int
+	m    reflect.Value
 	keys []reflect.Value
 }
 
@@ -98,4 +98,4 @@ func (iter *safeMapIterator) Next() (interface{}, interface{}) {
 
 func (iter *safeMapIterator) UnsafeNext() (unsafe.Pointer, unsafe.Pointer) {
 	panic("does not support unsafe operation")
-}
+}

+ 1 - 1
safe_slice.go

@@ -89,4 +89,4 @@ func (type2 *safeSliceType) Cap(obj interface{}) int {
 
 func (type2 *safeSliceType) UnsafeCap(ptr unsafe.Pointer) int {
 	panic("does not support unsafe operation")
-}
+}

+ 1 - 1
safe_struct.go

@@ -26,4 +26,4 @@ func (type2 *safeStructType) FieldByNameFunc(match func(string) bool) StructFiel
 		panic("field match condition not found in " + type2.Type.String())
 	}
 	return &safeField{StructField: field}
-}
+}

+ 1 - 1
safe_type.go

@@ -75,4 +75,4 @@ func (type2 *safeType) UnsafeSet(ptr unsafe.Pointer, val unsafe.Pointer) {
 
 func (type2 *safeType) AssignableTo(anotherType Type) bool {
 	return type2.Type1().AssignableTo(anotherType.Type1())
-}
+}

+ 2 - 2
test15/map_test.go

@@ -1,8 +1,8 @@
 package test
 
 import (
-	"testing"
 	"github.com/modern-go/reflect2"
+	"testing"
 )
 
 func Test_map(t *testing.T) {
@@ -15,4 +15,4 @@ func Test_map(t *testing.T) {
 	if m[1] != 1 {
 		t.Fail()
 	}
-}
+}

+ 2 - 2
tests/array_test.go

@@ -1,8 +1,8 @@
 package tests
 
 import (
-	"testing"
 	"github.com/modern-go/reflect2"
+	"testing"
 )
 
 func Test_array(t *testing.T) {
@@ -30,7 +30,7 @@ func Test_array(t *testing.T) {
 	t.Run("GetIndex", testOp(func(api reflect2.API) interface{} {
 		obj := [2]int{1, 2}
 		valType := api.TypeOf(obj).(reflect2.ArrayType)
-		return []interface{} {
+		return []interface{}{
 			valType.GetIndex(&obj, 0),
 			valType.GetIndex(&obj, 1),
 		}

+ 3 - 3
tests/int_test.go

@@ -1,12 +1,12 @@
 package tests
 
 import (
-	"testing"
+	"context"
 	"github.com/modern-go/reflect2"
 	"github.com/modern-go/test"
-	"unsafe"
 	"github.com/modern-go/test/must"
-	"context"
+	"testing"
+	"unsafe"
 )
 
 func Test_int(t *testing.T) {

+ 1 - 1
tests/map_elem_array_test.go

@@ -1,8 +1,8 @@
 package tests
 
 import (
-	"testing"
 	"github.com/modern-go/reflect2"
+	"testing"
 )
 
 func Test_map_elem_array(t *testing.T) {

+ 2 - 2
tests/map_elem_bytes_test.go

@@ -1,11 +1,11 @@
 package tests
 
 import (
-	"testing"
+	"context"
 	"github.com/modern-go/reflect2"
 	"github.com/modern-go/test"
 	"github.com/modern-go/test/must"
-	"context"
+	"testing"
 	"unsafe"
 )
 

+ 3 - 3
tests/map_elem_eface_test.go

@@ -1,12 +1,12 @@
 package tests
 
 import (
-	"testing"
 	"github.com/modern-go/reflect2"
 	"github.com/modern-go/test/must"
+	"testing"
 
-	"github.com/modern-go/test"
 	"context"
+	"github.com/modern-go/test"
 )
 
 func Test_map_elem_eface(t *testing.T) {
@@ -53,4 +53,4 @@ func Test_map_elem_eface(t *testing.T) {
 		must.Pass(!iter.HasNext(), "api", api)
 		return []interface{}{key1, elem1}
 	}))
-}
+}

+ 4 - 4
tests/map_elem_map_test.go

@@ -1,8 +1,8 @@
 package tests
 
 import (
-	"testing"
 	"github.com/modern-go/reflect2"
+	"testing"
 )
 
 func Test_map_elem_map(t *testing.T) {
@@ -15,9 +15,9 @@ func Test_map_elem_map(t *testing.T) {
 	t.Run("SetIndex", testOp(func(api reflect2.API) interface{} {
 		obj := map[int]map[int]int{}
 		valType := api.TypeOf(obj).(reflect2.MapType)
-		valType.SetIndex(&obj, pInt(2), pMap(map[int]int{4:4}))
-		valType.SetIndex(&obj, pInt(3), pMap(map[int]int{9:9}))
+		valType.SetIndex(&obj, pInt(2), pMap(map[int]int{4: 4}))
+		valType.SetIndex(&obj, pInt(3), pMap(map[int]int{9: 9}))
 		valType.SetIndex(&obj, pInt(3), pMap(nil))
 		return obj
 	}))
-}
+}

+ 1 - 1
tests/map_elem_struct_test.go

@@ -1,8 +1,8 @@
 package tests
 
 import (
-	"testing"
 	"github.com/modern-go/reflect2"
+	"testing"
 	"time"
 )
 

+ 1 - 1
tests/map_key_eface_test.go

@@ -1,9 +1,9 @@
 package tests
 
 import (
-	"testing"
 	"github.com/modern-go/reflect2"
 	"github.com/modern-go/test/must"
+	"testing"
 )
 
 func Test_map_key_eface(t *testing.T) {

+ 1 - 1
tests/map_key_iface_test.go

@@ -1,9 +1,9 @@
 package tests
 
 import (
-	"testing"
 	"github.com/modern-go/reflect2"
 	"github.com/modern-go/test/must"
+	"testing"
 )
 
 type intError int

+ 3 - 3
tests/map_key_ptr_test.go

@@ -1,13 +1,13 @@
 package tests
 
 import (
-	"testing"
 	"github.com/modern-go/reflect2"
-	"github.com/modern-go/test/must"
 	"github.com/modern-go/test"
+	"github.com/modern-go/test/must"
+	"testing"
 
-	"unsafe"
 	"context"
+	"unsafe"
 )
 
 func Test_map_key_ptr(t *testing.T) {

+ 3 - 3
tests/map_test.go

@@ -1,14 +1,14 @@
 package tests
 
 import (
-	"testing"
 	"github.com/modern-go/reflect2"
 	"github.com/modern-go/test/must"
+	"testing"
 
+	"context"
 	"github.com/modern-go/test"
-	"unsafe"
 	"reflect"
-	"context"
+	"unsafe"
 )
 
 func Test_map(t *testing.T) {

+ 2 - 2
tests/op_test.go

@@ -4,9 +4,9 @@ import (
 	"github.com/modern-go/reflect2"
 	"testing"
 
-	"github.com/modern-go/test/must"
-	"github.com/modern-go/test"
 	"context"
+	"github.com/modern-go/test"
+	"github.com/modern-go/test/must"
 )
 
 func testOp(f func(api reflect2.API) interface{}) func(t *testing.T) {

+ 1 - 1
tests/slice_array_test.go

@@ -1,8 +1,8 @@
 package tests
 
 import (
-	"testing"
 	"github.com/modern-go/reflect2"
+	"testing"
 )
 
 func Test_slice_array(t *testing.T) {

+ 2 - 2
tests/slice_bytes_test.go

@@ -1,8 +1,8 @@
 package tests
 
 import (
-	"testing"
 	"github.com/modern-go/reflect2"
+	"testing"
 )
 
 func Test_slice_bytes(t *testing.T) {
@@ -15,4 +15,4 @@ func Test_slice_bytes(t *testing.T) {
 		valType.SetIndex(&obj, 1, &elem2)
 		return obj
 	}))
-}
+}

+ 3 - 3
tests/slice_eface_test.go

@@ -1,14 +1,14 @@
 package tests
 
 import (
-	"testing"
 	"github.com/modern-go/reflect2"
 	"github.com/modern-go/test"
+	"testing"
 
+	"context"
 	"github.com/modern-go/test/must"
-	"unsafe"
 	"github.com/modern-go/test/should"
-	"context"
+	"unsafe"
 )
 
 func Test_slice_eface(t *testing.T) {

+ 4 - 4
tests/slice_iface_test.go

@@ -1,14 +1,14 @@
 package tests
 
 import (
-	"testing"
-	"github.com/modern-go/reflect2"
 	"errors"
+	"github.com/modern-go/reflect2"
 	"github.com/modern-go/test"
+	"testing"
 
-	"unsafe"
-	"github.com/modern-go/test/must"
 	"context"
+	"github.com/modern-go/test/must"
+	"unsafe"
 )
 
 func Test_slice_iface(t *testing.T) {

+ 11 - 11
tests/slice_map_test.go

@@ -1,27 +1,27 @@
 package tests
 
 import (
-	"testing"
 	"github.com/modern-go/reflect2"
+	"testing"
 )
 
 func Test_slice_map(t *testing.T) {
 	t.Run("MakeSlice", testOp(func(api reflect2.API) interface{} {
 		valType := api.TypeOf([]map[int]int{}).(reflect2.SliceType)
 		obj := valType.MakeSlice(5, 10)
-		(*obj.(*[]map[int]int))[0] = map[int]int{1:1}
-		(*obj.(*[]map[int]int))[4] = map[int]int{2:2}
+		(*obj.(*[]map[int]int))[0] = map[int]int{1: 1}
+		(*obj.(*[]map[int]int))[4] = map[int]int{2: 2}
 		return obj
 	}))
 	t.Run("SetIndex", testOp(func(api reflect2.API) interface{} {
 		obj := []map[int]int{{1: 1}, nil}
 		valType := api.TypeOf(obj).(reflect2.SliceType)
-		valType.SetIndex(&obj, 0, &map[int]int{10:10})
-		valType.SetIndex(&obj, 1, &map[int]int{2:2})
+		valType.SetIndex(&obj, 0, &map[int]int{10: 10})
+		valType.SetIndex(&obj, 1, &map[int]int{2: 2})
 		return obj
 	}))
 	t.Run("GetIndex", testOp(func(api reflect2.API) interface{} {
-		obj := []map[int]int{{1:1}, nil}
+		obj := []map[int]int{{1: 1}, nil}
 		valType := api.TypeOf(obj).(reflect2.SliceType)
 		return []interface{}{
 			valType.GetIndex(&obj, 0),
@@ -30,12 +30,12 @@ func Test_slice_map(t *testing.T) {
 	}))
 	t.Run("Append", testOp(func(api reflect2.API) interface{} {
 		obj := make([]map[int]int, 2, 3)
-		obj[0] = map[int]int{1:1}
-		obj[1] = map[int]int{2:2}
+		obj[0] = map[int]int{1: 1}
+		obj[1] = map[int]int{2: 2}
 		valType := api.TypeOf(obj).(reflect2.SliceType)
-		valType.Append(&obj, &map[int]int{3:3})
+		valType.Append(&obj, &map[int]int{3: 3})
 		// will trigger grow
-		valType.Append(&obj, &map[int]int{4:4})
+		valType.Append(&obj, &map[int]int{4: 4})
 		return obj
 	}))
-}
+}

+ 3 - 3
tests/slice_ptr_test.go

@@ -1,13 +1,13 @@
 package tests
 
 import (
-	"testing"
 	"github.com/modern-go/reflect2"
 	"github.com/modern-go/test"
+	"testing"
 
-	"unsafe"
-	"github.com/modern-go/test/must"
 	"context"
+	"github.com/modern-go/test/must"
+	"unsafe"
 )
 
 func Test_slice_ptr(t *testing.T) {

+ 2 - 2
tests/slice_string_test.go

@@ -1,8 +1,8 @@
 package tests
 
 import (
-	"testing"
 	"github.com/modern-go/reflect2"
+	"testing"
 )
 
 func Test_slice_string(t *testing.T) {
@@ -15,4 +15,4 @@ func Test_slice_string(t *testing.T) {
 		valType.SetIndex(&obj, 1, &elem2)
 		return obj
 	}))
-}
+}

+ 2 - 2
tests/slice_struct_test.go

@@ -1,8 +1,8 @@
 package tests
 
 import (
-	"testing"
 	"github.com/modern-go/reflect2"
+	"testing"
 )
 
 func Test_slice_struct(t *testing.T) {
@@ -50,4 +50,4 @@ func Test_slice_struct(t *testing.T) {
 		valType.SetIndex(&obj, 1, &TestObject{})
 		return obj
 	}))
-}
+}

+ 2 - 2
tests/slice_test.go

@@ -1,12 +1,12 @@
 package tests
 
 import (
-	"testing"
 	"github.com/modern-go/reflect2"
 	"github.com/modern-go/test"
+	"testing"
 
-	"github.com/modern-go/test/must"
 	"context"
+	"github.com/modern-go/test/must"
 )
 
 func Test_slice(t *testing.T) {

+ 2 - 2
tests/struct_eface_test.go

@@ -1,8 +1,8 @@
 package tests
 
 import (
-	"testing"
 	"github.com/modern-go/reflect2"
+	"testing"
 )
 
 func Test_struct_eface(t *testing.T) {
@@ -25,4 +25,4 @@ func Test_struct_eface(t *testing.T) {
 		field1 := valType.FieldByName("Field1")
 		return field1.Get(&obj)
 	}))
-}
+}

+ 3 - 3
tests/struct_ptr_test.go

@@ -3,10 +3,10 @@ package tests
 import (
 	"testing"
 
+	"context"
 	"github.com/modern-go/reflect2"
-	"github.com/modern-go/test/must"
 	"github.com/modern-go/test"
-	"context"
+	"github.com/modern-go/test/must"
 )
 
 func Test_struct_ptr(t *testing.T) {
@@ -22,4 +22,4 @@ func Test_struct_ptr(t *testing.T) {
 		valType := reflect2.TypeOf(TestObject{})
 		must.Equal(TestObject{}, valType.Indirect(&TestObject{}))
 	}))
-}
+}

+ 3 - 3
tests/struct_test.go

@@ -1,13 +1,13 @@
 package tests
 
 import (
-	"testing"
 	"github.com/modern-go/reflect2"
 	"github.com/modern-go/test"
+	"testing"
 
-	"unsafe"
-	"github.com/modern-go/test/must"
 	"context"
+	"github.com/modern-go/test/must"
+	"unsafe"
 )
 
 func Test_struct(t *testing.T) {

+ 1 - 1
type_map.go

@@ -1,10 +1,10 @@
 package reflect2
 
 import (
-	"unsafe"
 	"reflect"
 	"runtime"
 	"strings"
+	"unsafe"
 )
 
 // typelinks1 for 1.5 ~ 1.6

+ 1 - 1
unsafe_array.go

@@ -1,8 +1,8 @@
 package reflect2
 
 import (
-	"unsafe"
 	"reflect"
+	"unsafe"
 )
 
 type UnsafeArrayType struct {

+ 2 - 2
unsafe_eface.go

@@ -1,8 +1,8 @@
 package reflect2
 
 import (
-	"unsafe"
 	"reflect"
+	"unsafe"
 )
 
 type eface struct {
@@ -56,4 +56,4 @@ func (type2 *UnsafeEFaceType) Indirect(obj interface{}) interface{} {
 
 func (type2 *UnsafeEFaceType) UnsafeIndirect(ptr unsafe.Pointer) interface{} {
 	return *(*interface{})(ptr)
-}
+}

+ 2 - 2
unsafe_iface.go

@@ -1,8 +1,8 @@
 package reflect2
 
 import (
-	"unsafe"
 	"reflect"
+	"unsafe"
 )
 
 type iface struct {
@@ -61,4 +61,4 @@ func (type2 *UnsafeIFaceType) UnsafeIsNil(ptr unsafe.Pointer) bool {
 		return true
 	}
 	return false
-}
+}

+ 1 - 1
unsafe_link.go

@@ -67,4 +67,4 @@ func add(p unsafe.Pointer, x uintptr, whySafe string) unsafe.Pointer {
 // the benefit is to surface this assumption at the call site.)
 func arrayAt(p unsafe.Pointer, i int, eltSize uintptr, whySafe string) unsafe.Pointer {
 	return add(p, uintptr(i)*eltSize, "i < len")
-}
+}

+ 1 - 1
unsafe_ptr.go

@@ -1,8 +1,8 @@
 package reflect2
 
 import (
-	"unsafe"
 	"reflect"
+	"unsafe"
 )
 
 type UnsafePtrType struct {

+ 1 - 1
unsafe_slice.go

@@ -1,8 +1,8 @@
 package reflect2
 
 import (
-	"unsafe"
 	"reflect"
+	"unsafe"
 )
 
 // sliceHeader is a safe version of SliceHeader used within this package.

+ 1 - 1
unsafe_struct.go

@@ -56,4 +56,4 @@ func (type2 *UnsafeStructType) FieldByNameFunc(match func(string) bool) StructFi
 		panic("field match condition not found in " + type2.Type.String())
 	}
 	return newUnsafeStructField(type2, structField)
-}
+}

+ 2 - 2
unsafe_type.go

@@ -1,8 +1,8 @@
 package reflect2
 
 import (
-	"unsafe"
 	"reflect"
+	"unsafe"
 )
 
 type unsafeType struct {
@@ -15,7 +15,7 @@ func newUnsafeType(cfg *frozenConfig, type1 reflect.Type) *unsafeType {
 	return &unsafeType{
 		safeType: safeType{
 			Type: type1,
-			cfg: cfg,
+			cfg:  cfg,
 		},
 		rtype:    unpackEFace(type1).data,
 		ptrRType: unpackEFace(reflect.PtrTo(type1)).data,