mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-29 11:00:29 +00:00
LibJS: Optimize PropertyName and StringPrototype for size
We can reduce the amount of padding the compiler adds in order to ensure data alignment of member variables by ordering the types in a struct by size in decending order. Found By PVS-Studio: https://pvs-studio.com/en/docs/warnings/v802/
This commit is contained in:
parent
d347432a9e
commit
1b00ddf07e
Notes:
sideshowbarker
2024-07-18 02:51:40 +09:00
Author: https://github.com/bgianfo Commit: https://github.com/SerenityOS/serenity/commit/1b00ddf07e9 Pull-request: https://github.com/SerenityOS/serenity/pull/10418
3 changed files with 9 additions and 9 deletions
|
@ -74,8 +74,8 @@ public:
|
|||
}
|
||||
|
||||
PropertyName(FlyString string, StringMayBeNumber string_may_be_number = StringMayBeNumber::Yes)
|
||||
: m_type(Type::String)
|
||||
, m_string_may_be_number(string_may_be_number == StringMayBeNumber::Yes)
|
||||
: m_string_may_be_number(string_may_be_number == StringMayBeNumber::Yes)
|
||||
, m_type(Type::String)
|
||||
, m_string(move(string))
|
||||
{
|
||||
VERIFY(!m_string.is_null());
|
||||
|
@ -184,11 +184,11 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
Type m_type { Type::Invalid };
|
||||
bool m_string_may_be_number { true };
|
||||
Type m_type { Type::Invalid };
|
||||
u32 m_number { 0 };
|
||||
FlyString m_string;
|
||||
Symbol* m_symbol { nullptr };
|
||||
u32 m_number { 0 };
|
||||
};
|
||||
|
||||
struct PropertyNameTraits : public Traits<PropertyName> {
|
||||
|
|
|
@ -63,18 +63,18 @@ CodePoint code_point_at(Utf16View const& string, size_t position)
|
|||
auto code_point = static_cast<u32>(first);
|
||||
|
||||
if (!Utf16View::is_high_surrogate(first) && !Utf16View::is_low_surrogate(first))
|
||||
return { code_point, 1, false };
|
||||
return { false, code_point, 1 };
|
||||
|
||||
if (Utf16View::is_low_surrogate(first) || (position + 1 == string.length_in_code_units()))
|
||||
return { code_point, 1, true };
|
||||
return { true, code_point, 1 };
|
||||
|
||||
auto second = string.code_unit_at(position + 1);
|
||||
|
||||
if (!Utf16View::is_low_surrogate(second))
|
||||
return { code_point, 1, true };
|
||||
return { true, code_point, 1 };
|
||||
|
||||
code_point = Utf16View::decode_surrogate_pair(first, second);
|
||||
return { code_point, 2, false };
|
||||
return { false, code_point, 2 };
|
||||
}
|
||||
|
||||
// 6.1.4.1 StringIndexOf ( string, searchValue, fromIndex ), https://tc39.es/ecma262/#sec-stringindexof
|
||||
|
|
|
@ -11,9 +11,9 @@
|
|||
namespace JS {
|
||||
|
||||
struct CodePoint {
|
||||
bool is_unpaired_surrogate { false };
|
||||
u32 code_point { 0 };
|
||||
size_t code_unit_count { 0 };
|
||||
bool is_unpaired_surrogate { false };
|
||||
};
|
||||
|
||||
CodePoint code_point_at(Utf16View const& string, size_t position);
|
||||
|
|
Loading…
Reference in a new issue