internal/atlas: use bit manipulation for function power of 2 -like functions (#2915)

Closes #2914
This commit is contained in:
Mykhailo Lohachov 2024-02-25 02:06:52 +09:00 committed by GitHub
parent 64cb6cf8a9
commit 012fe52b6f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 12 deletions

View File

@ -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 {

View File

@ -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 {