Skip to content

Commit

Permalink
Add API Document
Browse files Browse the repository at this point in the history
  • Loading branch information
goccy committed Jul 5, 2020
1 parent 5c1bf57 commit 6320687
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bechmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func valueFromReflect(v interface{}) {
}

func valueFromGoReflect(v interface{}) {
f(goreflect.ValueOf(v))
f(goreflect.ValueNoEscapeOf(v))
}

func Benchmark_TypeOf_Reflect(b *testing.B) {
Expand Down
18 changes: 15 additions & 3 deletions reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,12 @@ func TypeOf(v interface{}) *Type {
return value.typ
}

// TypeID returns unique type identifier of v.
func TypeID(v interface{}) uintptr {
return uintptr(unsafe.Pointer(TypeOf(v)))
}

func ValueOf(v interface{}) Value {
func valueOf(v interface{}) Value {
if v == nil {
return Value{}
}
Expand All @@ -283,23 +284,34 @@ func ValueOf(v interface{}) Value {
return value
}

func EscapeValueOf(v interface{}) Value {
// ValueOf returns a new Value initialized to the concrete value
// stored in the interface i. ValueOf(nil) returns the zero Value.
func ValueOf(v interface{}) Value {
escape(v)
return ValueOf(v)
return valueOf(v)
}

// ValueNoEscapeOf no escape of ValueOf.
func ValueNoEscapeOf(v interface{}) Value {
return valueOf(v)
}

// ToReflectType convert *Type to reflect.Type
func ToReflectType(t *Type) reflect.Type {
return type_toType(t)
}

// ToReflectValue convert Value to reflect.Value
func ToReflectValue(v Value) reflect.Value {
return *(*reflect.Value)(unsafe.Pointer(&v))
}

// ToType convert reflect.Type to *Type
func ToType(t reflect.Type) *Type {
return (*Type)(((*Value)(unsafe.Pointer(&t))).ptr)
}

// ToValue convert reflect.Value to Value
func ToValue(v reflect.Value) Value {
return *(*Value)(unsafe.Pointer(&v))
}
Expand Down

0 comments on commit 6320687

Please sign in to comment.