LibJS: Make Optional<StringTableIndex> use less space

We can use the index's invalid state to signal an empty optional.
This makes Optional<StringTableIndex> 4 bytes instead of 8,
shrinking every bytecode instruction that uses these.
This commit is contained in:
Andreas Kling 2025-04-05 21:46:37 +02:00 committed by Andreas Kling
parent f1a54ef281
commit 42cc481091
Notes: github-actions[bot] 2025-04-06 00:06:34 +00:00
3 changed files with 110 additions and 6 deletions

View file

@ -11,12 +11,12 @@ namespace JS::Bytecode {
StringTableIndex StringTable::insert(String string)
{
m_strings.append(move(string));
return m_strings.size() - 1;
return { static_cast<u32>(m_strings.size() - 1) };
}
String const& StringTable::get(StringTableIndex index) const
{
return m_strings[index.value()];
return m_strings[index.value];
}
void StringTable::dump() const