mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
graphicsdriver/opengl/gl: Reduce reflect usage
This commit is contained in:
parent
050b788843
commit
f4a1f90d92
@ -28,25 +28,23 @@ func Ptr(data interface{}) unsafe.Pointer {
|
|||||||
return unsafe.Pointer(nil)
|
return unsafe.Pointer(nil)
|
||||||
}
|
}
|
||||||
var addr unsafe.Pointer
|
var addr unsafe.Pointer
|
||||||
v := reflect.ValueOf(data)
|
switch v := data.(type) {
|
||||||
switch v.Type().Kind() {
|
case *uint8:
|
||||||
case reflect.Ptr:
|
addr = unsafe.Pointer(v)
|
||||||
e := v.Elem()
|
case *uint16:
|
||||||
switch e.Kind() {
|
addr = unsafe.Pointer(v)
|
||||||
case
|
case *float32:
|
||||||
reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
|
addr = unsafe.Pointer(v)
|
||||||
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,
|
case uintptr:
|
||||||
reflect.Float32, reflect.Float64:
|
addr = unsafe.Pointer(v)
|
||||||
addr = unsafe.Pointer(e.UnsafeAddr())
|
case []uint8:
|
||||||
default:
|
addr = unsafe.Pointer(&v[0])
|
||||||
panic(fmt.Errorf("unsupported pointer to type %s; must be a slice or pointer to a singular scalar value or the first element of an array or slice", e.Kind()))
|
case []uint16:
|
||||||
}
|
addr = unsafe.Pointer(&v[0])
|
||||||
case reflect.Uintptr:
|
case []float32:
|
||||||
addr = unsafe.Pointer(v.Pointer())
|
addr = unsafe.Pointer(&v[0])
|
||||||
case reflect.Slice:
|
|
||||||
addr = unsafe.Pointer(v.Index(0).UnsafeAddr())
|
|
||||||
default:
|
default:
|
||||||
panic(fmt.Errorf("unsupported type %s; must be a slice or pointer to a singular scalar value or the first element of an array or slice", v.Type()))
|
panic(fmt.Errorf("unsupported type %T; must be a slice or pointer to a singular scalar value or the first element of an array or slice", v))
|
||||||
}
|
}
|
||||||
return addr
|
return addr
|
||||||
}
|
}
|
||||||
|
@ -23,25 +23,23 @@ func Ptr(data interface{}) unsafe.Pointer {
|
|||||||
return unsafe.Pointer(nil)
|
return unsafe.Pointer(nil)
|
||||||
}
|
}
|
||||||
var addr unsafe.Pointer
|
var addr unsafe.Pointer
|
||||||
v := reflect.ValueOf(data)
|
switch v := data.(type) {
|
||||||
switch v.Type().Kind() {
|
case *uint8:
|
||||||
case reflect.Ptr:
|
addr = unsafe.Pointer(v)
|
||||||
e := v.Elem()
|
case *uint16:
|
||||||
switch e.Kind() {
|
addr = unsafe.Pointer(v)
|
||||||
case
|
case *float32:
|
||||||
reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
|
addr = unsafe.Pointer(v)
|
||||||
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,
|
case uintptr:
|
||||||
reflect.Float32, reflect.Float64:
|
addr = unsafe.Pointer(v)
|
||||||
addr = unsafe.Pointer(e.UnsafeAddr())
|
case []uint8:
|
||||||
default:
|
addr = unsafe.Pointer(&v[0])
|
||||||
panic(fmt.Errorf("unsupported pointer to type %s; must be a slice or pointer to a singular scalar value or the first element of an array or slice", e.Kind()))
|
case []uint16:
|
||||||
}
|
addr = unsafe.Pointer(&v[0])
|
||||||
case reflect.Uintptr:
|
case []float32:
|
||||||
addr = unsafe.Pointer(v.Pointer())
|
addr = unsafe.Pointer(&v[0])
|
||||||
case reflect.Slice:
|
|
||||||
addr = unsafe.Pointer(v.Index(0).UnsafeAddr())
|
|
||||||
default:
|
default:
|
||||||
panic(fmt.Errorf("unsupported type %s; must be a slice or pointer to a singular scalar value or the first element of an array or slice", v.Type()))
|
panic(fmt.Errorf("unsupported type %T; must be a slice or pointer to a singular scalar value or the first element of an array or slice", v))
|
||||||
}
|
}
|
||||||
return addr
|
return addr
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user