mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-11 19:48:54 +01:00
internal/atlas: use bit manipulation for function power of 2 -like functions (#2915)
Closes #2914
This commit is contained in:
parent
64cb6cf8a9
commit
012fe52b6f
@ -18,6 +18,7 @@ import (
|
||||
"fmt"
|
||||
"image"
|
||||
"math"
|
||||
"math/bits"
|
||||
"runtime"
|
||||
"sync"
|
||||
|
||||
@ -885,11 +886,7 @@ func floorPowerOf2(x int) int {
|
||||
if x <= 0 {
|
||||
return 0
|
||||
}
|
||||
p2 := 1
|
||||
for p2*2 <= x {
|
||||
p2 *= 2
|
||||
}
|
||||
return p2
|
||||
return 1 << (bits.Len(uint(x)) - 1)
|
||||
}
|
||||
|
||||
func BeginFrame(graphicsDriver graphicsdriver.Graphics) error {
|
||||
|
@ -32,13 +32,7 @@ func isPositivePowerOf2(x int) bool {
|
||||
if x <= 0 {
|
||||
return false
|
||||
}
|
||||
for x > 1 {
|
||||
if x/2*2 != x {
|
||||
return false
|
||||
}
|
||||
x /= 2
|
||||
}
|
||||
return true
|
||||
return x&(x-1) == 0
|
||||
}
|
||||
|
||||
func NewPage(initWidth, initHeight int, maxSize int) *Page {
|
||||
|
Loading…
Reference in New Issue
Block a user