1
0
mirror of https://github.com/golang/go synced 2024-11-22 00:24:41 -07:00

Remove unnecessary casts in Get() methods.

Cleaner, but also results in a 25%+ performance improvement for Get()/SetValue() on my machine.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/3072041
This commit is contained in:
Kyle Consalus 2010-11-12 15:25:25 -08:00 committed by Rob Pike
parent 48cc88d063
commit 81cb189a06

View File

@ -141,7 +141,7 @@ type FloatValue struct {
// Get returns the underlying int value. // Get returns the underlying int value.
func (v *FloatValue) Get() float64 { func (v *FloatValue) Get() float64 {
switch v.typ.(*FloatType).Kind() { switch v.typ.Kind() {
case Float: case Float:
return float64(*(*float)(v.addr)) return float64(*(*float)(v.addr))
case Float32: case Float32:
@ -157,7 +157,7 @@ func (v *FloatValue) Set(x float64) {
if !v.canSet { if !v.canSet {
panic(cannotSet) panic(cannotSet)
} }
switch v.typ.(*FloatType).Kind() { switch v.typ.Kind() {
default: default:
panic("reflect: invalid float kind") panic("reflect: invalid float kind")
case Float: case Float:
@ -190,7 +190,7 @@ type ComplexValue struct {
// Get returns the underlying complex value. // Get returns the underlying complex value.
func (v *ComplexValue) Get() complex128 { func (v *ComplexValue) Get() complex128 {
switch v.typ.(*ComplexType).Kind() { switch v.typ.Kind() {
case Complex: case Complex:
return complex128(*(*complex)(v.addr)) return complex128(*(*complex)(v.addr))
case Complex64: case Complex64:
@ -206,7 +206,7 @@ func (v *ComplexValue) Set(x complex128) {
if !v.canSet { if !v.canSet {
panic(cannotSet) panic(cannotSet)
} }
switch v.typ.(*ComplexType).Kind() { switch v.typ.Kind() {
default: default:
panic("reflect: invalid complex kind") panic("reflect: invalid complex kind")
case Complex: case Complex:
@ -228,7 +228,7 @@ type IntValue struct {
// Get returns the underlying int value. // Get returns the underlying int value.
func (v *IntValue) Get() int64 { func (v *IntValue) Get() int64 {
switch v.typ.(*IntType).Kind() { switch v.typ.Kind() {
case Int: case Int:
return int64(*(*int)(v.addr)) return int64(*(*int)(v.addr))
case Int8: case Int8:
@ -248,7 +248,7 @@ func (v *IntValue) Set(x int64) {
if !v.canSet { if !v.canSet {
panic(cannotSet) panic(cannotSet)
} }
switch v.typ.(*IntType).Kind() { switch v.typ.Kind() {
default: default:
panic("reflect: invalid int kind") panic("reflect: invalid int kind")
case Int: case Int:
@ -306,7 +306,7 @@ type UintValue struct {
// Get returns the underlying uuint value. // Get returns the underlying uuint value.
func (v *UintValue) Get() uint64 { func (v *UintValue) Get() uint64 {
switch v.typ.(*UintType).Kind() { switch v.typ.Kind() {
case Uint: case Uint:
return uint64(*(*uint)(v.addr)) return uint64(*(*uint)(v.addr))
case Uint8: case Uint8:
@ -328,7 +328,7 @@ func (v *UintValue) Set(x uint64) {
if !v.canSet { if !v.canSet {
panic(cannotSet) panic(cannotSet)
} }
switch v.typ.(*UintType).Kind() { switch v.typ.Kind() {
default: default:
panic("reflect: invalid uint kind") panic("reflect: invalid uint kind")
case Uint: case Uint: