mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-04 05:20:30 +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
Notes:
sideshowbarker
2024-07-17 16:23:55 +09:00
Author: https://github.com/tcl3 Commit: https://github.com/SerenityOS/serenity/commit/7096ea82f9 Pull-request: https://github.com/SerenityOS/serenity/pull/21593
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)
|
||||
|
|
|
@ -111,10 +111,9 @@ static i16 be_i16(u8 const* ptr)
|
|||
|
||||
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));
|
||||
}
|
||||
|
||||
enum class TransformationVersion {
|
||||
|
|
Loading…
Reference in a new issue