1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:48:11 +00:00

LibJS: Use String and move semantics in Bytecode::StringTable

Avoid creating new AK::String objects when we already have one.
This commit is contained in:
Andreas Kling 2021-10-24 15:14:14 +02:00
parent 3117182c2e
commit 13f04e37e5
3 changed files with 5 additions and 5 deletions

View file

@ -97,9 +97,9 @@ public:
return m_current_basic_block->is_terminated();
}
StringTableIndex intern_string(StringView const& string)
StringTableIndex intern_string(String string)
{
return m_string_table->insert(string);
return m_string_table->insert(move(string));
}
bool is_in_generator_function() const { return m_is_in_generator_function; }

View file

@ -8,13 +8,13 @@
namespace JS::Bytecode {
StringTableIndex StringTable::insert(StringView string)
StringTableIndex StringTable::insert(String string)
{
for (size_t i = 0; i < m_strings.size(); i++) {
if (m_strings[i] == string)
return i;
}
m_strings.append(string);
m_strings.append(move(string));
return m_strings.size() - 1;
}

View file

@ -21,7 +21,7 @@ class StringTable {
public:
StringTable() = default;
StringTableIndex insert(StringView string);
StringTableIndex insert(String);
String const& get(StringTableIndex) const;
void dump() const;
bool is_empty() const { return m_strings.is_empty(); }