mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +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)
|
||||
}
|
||||
var addr unsafe.Pointer
|
||||
v := reflect.ValueOf(data)
|
||||
switch v.Type().Kind() {
|
||||
case reflect.Ptr:
|
||||
e := v.Elem()
|
||||
switch e.Kind() {
|
||||
case
|
||||
reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
|
||||
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,
|
||||
reflect.Float32, reflect.Float64:
|
||||
addr = unsafe.Pointer(e.UnsafeAddr())
|
||||
default:
|
||||
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 reflect.Uintptr:
|
||||
addr = unsafe.Pointer(v.Pointer())
|
||||
case reflect.Slice:
|
||||
addr = unsafe.Pointer(v.Index(0).UnsafeAddr())
|
||||
switch v := data.(type) {
|
||||
case *uint8:
|
||||
addr = unsafe.Pointer(v)
|
||||
case *uint16:
|
||||
addr = unsafe.Pointer(v)
|
||||
case *float32:
|
||||
addr = unsafe.Pointer(v)
|
||||
case uintptr:
|
||||
addr = unsafe.Pointer(v)
|
||||
case []uint8:
|
||||
addr = unsafe.Pointer(&v[0])
|
||||
case []uint16:
|
||||
addr = unsafe.Pointer(&v[0])
|
||||
case []float32:
|
||||
addr = unsafe.Pointer(&v[0])
|
||||
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
|
||||
}
|
||||
|
@ -23,25 +23,23 @@ func Ptr(data interface{}) unsafe.Pointer {
|
||||
return unsafe.Pointer(nil)
|
||||
}
|
||||
var addr unsafe.Pointer
|
||||
v := reflect.ValueOf(data)
|
||||
switch v.Type().Kind() {
|
||||
case reflect.Ptr:
|
||||
e := v.Elem()
|
||||
switch e.Kind() {
|
||||
case
|
||||
reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
|
||||
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,
|
||||
reflect.Float32, reflect.Float64:
|
||||
addr = unsafe.Pointer(e.UnsafeAddr())
|
||||
default:
|
||||
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 reflect.Uintptr:
|
||||
addr = unsafe.Pointer(v.Pointer())
|
||||
case reflect.Slice:
|
||||
addr = unsafe.Pointer(v.Index(0).UnsafeAddr())
|
||||
switch v := data.(type) {
|
||||
case *uint8:
|
||||
addr = unsafe.Pointer(v)
|
||||
case *uint16:
|
||||
addr = unsafe.Pointer(v)
|
||||
case *float32:
|
||||
addr = unsafe.Pointer(v)
|
||||
case uintptr:
|
||||
addr = unsafe.Pointer(v)
|
||||
case []uint8:
|
||||
addr = unsafe.Pointer(&v[0])
|
||||
case []uint16:
|
||||
addr = unsafe.Pointer(&v[0])
|
||||
case []float32:
|
||||
addr = unsafe.Pointer(&v[0])
|
||||
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user