mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:07:36 +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
3 changed files with 9 additions and 9 deletions
|
@ -74,8 +74,8 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
PropertyName(FlyString string, StringMayBeNumber string_may_be_number = StringMayBeNumber::Yes)
|
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))
|
, m_string(move(string))
|
||||||
{
|
{
|
||||||
VERIFY(!m_string.is_null());
|
VERIFY(!m_string.is_null());
|
||||||
|
@ -184,11 +184,11 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Type m_type { Type::Invalid };
|
|
||||||
bool m_string_may_be_number { true };
|
bool m_string_may_be_number { true };
|
||||||
|
Type m_type { Type::Invalid };
|
||||||
|
u32 m_number { 0 };
|
||||||
FlyString m_string;
|
FlyString m_string;
|
||||||
Symbol* m_symbol { nullptr };
|
Symbol* m_symbol { nullptr };
|
||||||
u32 m_number { 0 };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PropertyNameTraits : public Traits<PropertyName> {
|
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);
|
auto code_point = static_cast<u32>(first);
|
||||||
|
|
||||||
if (!Utf16View::is_high_surrogate(first) && !Utf16View::is_low_surrogate(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()))
|
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);
|
auto second = string.code_unit_at(position + 1);
|
||||||
|
|
||||||
if (!Utf16View::is_low_surrogate(second))
|
if (!Utf16View::is_low_surrogate(second))
|
||||||
return { code_point, 1, true };
|
return { true, code_point, 1 };
|
||||||
|
|
||||||
code_point = Utf16View::decode_surrogate_pair(first, second);
|
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
|
// 6.1.4.1 StringIndexOf ( string, searchValue, fromIndex ), https://tc39.es/ecma262/#sec-stringindexof
|
||||||
|
|
|
@ -11,9 +11,9 @@
|
||||||
namespace JS {
|
namespace JS {
|
||||||
|
|
||||||
struct CodePoint {
|
struct CodePoint {
|
||||||
|
bool is_unpaired_surrogate { false };
|
||||||
u32 code_point { 0 };
|
u32 code_point { 0 };
|
||||||
size_t code_unit_count { 0 };
|
size_t code_unit_count { 0 };
|
||||||
bool is_unpaired_surrogate { false };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
CodePoint code_point_at(Utf16View const& string, size_t position);
|
CodePoint code_point_at(Utf16View const& string, size_t position);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue