diff options
author | Andreas Kling <kling@serenityos.org> | 2022-11-26 19:01:55 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-12-08 23:36:17 +0000 |
commit | e70f944e11f6d25d8365363ecd2fdb48a5dbd411 (patch) | |
tree | 3fd4624970eb055c503a40d5df0c2da8a2acee78 | |
parent | e647ad2ce3f02db755f8001f78413452e134234a (diff) | |
download | serenity-e70f944e11f6d25d8365363ecd2fdb48a5dbd411.zip |
LibJS: Rearrange ASTNode members so there's a padding hole at the end
ASTNode inherits from RefCounted, which has a single 32-bit member.
This means that there's a 32-bit padding hole after RefCounted,
where we are free to put something (or it will go to waste!)
This patch moves ASTNode::m_start_offset into that padding hole,
and we now have a 32-bit padding hole at the end of ASTNode instead.
This will allow ASTNode subclasses to put things in the ASTNode hole
by moving them to the head of the member list.
-rw-r--r-- | Userland/Libraries/LibJS/AST.cpp | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/AST.h | 4 |
2 files changed, 5 insertions, 3 deletions
diff --git a/Userland/Libraries/LibJS/AST.cpp b/Userland/Libraries/LibJS/AST.cpp index caf127db71..23d7de8836 100644 --- a/Userland/Libraries/LibJS/AST.cpp +++ b/Userland/Libraries/LibJS/AST.cpp @@ -62,8 +62,8 @@ private: }; ASTNode::ASTNode(SourceRange source_range) - : m_source_code(source_range.code) - , m_start_offset(source_range.start.offset) + : m_start_offset(source_range.start.offset) + , m_source_code(source_range.code) , m_end_offset(source_range.end.offset) { } diff --git a/Userland/Libraries/LibJS/AST.h b/Userland/Libraries/LibJS/AST.h index a583f917bd..d757eba77a 100644 --- a/Userland/Libraries/LibJS/AST.h +++ b/Userland/Libraries/LibJS/AST.h @@ -90,8 +90,10 @@ protected: explicit ASTNode(SourceRange); private: - RefPtr<SourceCode> m_source_code; + // NOTE: These members are carefully ordered so that `m_start_offset` is packed with the padding after RefCounted::m_ref_count. + // This creates a 4-byte padding hole after `m_end_offset` which is used to pack subclasses better. u32 m_start_offset { 0 }; + RefPtr<SourceCode> m_source_code; u32 m_end_offset { 0 }; }; |