LibJS: Cache a FlyString for "this" to speed up variable lookup

We were hitting strcmp() in every variable lookup to see if the lookup
was for "this". Caching a FlyString("this") turns that check into one
pointer comparison instead. :^)
This commit is contained in:
Andreas Kling 2020-04-12 20:40:02 +02:00
parent 26a8984d03
commit 110ca6b0b6
Notes: sideshowbarker 2024-07-19 07:40:02 +09:00

View file

@ -158,7 +158,8 @@ void Interpreter::set_variable(const FlyString& name, Value value, bool first_as
Optional<Value> Interpreter::get_variable(const FlyString& name)
{
if (name == "this")
static FlyString this_name = "this";
if (name == this_name)
return this_value();
for (ssize_t i = m_scope_stack.size() - 1; i >= 0; --i) {