mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:07:36 +00:00
LibGfx: Use count_leading_zeroes
to calculate nearest power of 2
This removes the possibility of an infinite loop.
This commit is contained in:
parent
6e4c97a328
commit
7096ea82f9
2 changed files with 6 additions and 8 deletions
|
@ -63,10 +63,9 @@ static constexpr u32 WOFF_SIGNATURE = 0x774F4646;
|
|||
|
||||
static u16 pow_2_less_than_or_equal(u16 x)
|
||||
{
|
||||
u16 result = 1;
|
||||
while (result < x)
|
||||
result <<= 1;
|
||||
return result;
|
||||
VERIFY(x > 0);
|
||||
VERIFY(x < 32769);
|
||||
return 1 << (sizeof(u16) * 8 - count_leading_zeroes<u16>(x - 1));
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtr<Font>> Font::try_load_from_file(DeprecatedString path, unsigned int index)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue