Commit 0d81b72e authored by Russ Cox's avatar Russ Cox

reflect: a few microoptimizations

Replace i < 0 || i >= x with uint(i) >= uint(x).
Shorten a few other code sequences.
Move the kind bits to the bottom of the flag word, to avoid shifts.

LGTM=r
R=r, bradfitz
CC=golang-codereviews
https://golang.org/cl/159020043
parent 5e713062
...@@ -60,7 +60,7 @@ func MakeFunc(typ Type, fn func(args []Value) (results []Value)) Value { ...@@ -60,7 +60,7 @@ func MakeFunc(typ Type, fn func(args []Value) (results []Value)) Value {
impl := &makeFuncImpl{code: code, stack: stack, typ: ftyp, fn: fn} impl := &makeFuncImpl{code: code, stack: stack, typ: ftyp, fn: fn}
return Value{t, unsafe.Pointer(impl), flag(Func) << flagKindShift} return Value{t, unsafe.Pointer(impl), flag(Func)}
} }
// makeFuncStub is an assembly function that is the code half of // makeFuncStub is an assembly function that is the code half of
...@@ -91,7 +91,7 @@ func makeMethodValue(op string, v Value) Value { ...@@ -91,7 +91,7 @@ func makeMethodValue(op string, v Value) Value {
// Ignoring the flagMethod bit, v describes the receiver, not the method type. // Ignoring the flagMethod bit, v describes the receiver, not the method type.
fl := v.flag & (flagRO | flagAddr | flagIndir) fl := v.flag & (flagRO | flagAddr | flagIndir)
fl |= flag(v.typ.Kind()) << flagKindShift fl |= flag(v.typ.Kind())
rcvr := Value{v.typ, v.ptr, fl} rcvr := Value{v.typ, v.ptr, fl}
// v.Type returns the actual type of the method value. // v.Type returns the actual type of the method value.
...@@ -118,7 +118,7 @@ func makeMethodValue(op string, v Value) Value { ...@@ -118,7 +118,7 @@ func makeMethodValue(op string, v Value) Value {
// but we want Interface() and other operations to fail early. // but we want Interface() and other operations to fail early.
methodReceiver(op, fv.rcvr, fv.method) methodReceiver(op, fv.rcvr, fv.method)
return Value{funcType, unsafe.Pointer(fv), v.flag&flagRO | flag(Func)<<flagKindShift} return Value{funcType, unsafe.Pointer(fv), v.flag&flagRO | flag(Func)}
} }
// methodValueCall is an assembly function that is the code half of // methodValueCall is an assembly function that is the code half of
......
...@@ -490,7 +490,7 @@ func (t *uncommonType) Method(i int) (m Method) { ...@@ -490,7 +490,7 @@ func (t *uncommonType) Method(i int) (m Method) {
if p.name != nil { if p.name != nil {
m.Name = *p.name m.Name = *p.name
} }
fl := flag(Func) << flagKindShift fl := flag(Func)
if p.pkgPath != nil { if p.pkgPath != nil {
m.PkgPath = *p.pkgPath m.PkgPath = *p.pkgPath
fl |= flagRO fl |= flagRO
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment