From 110ca6b0b60ce4cdcac64bb4184844e88c43bd3b Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 12 Apr 2020 20:40:02 +0200 Subject: [PATCH] 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. :^) --- Libraries/LibJS/Interpreter.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Libraries/LibJS/Interpreter.cpp b/Libraries/LibJS/Interpreter.cpp index 5bd91139e0..bd2d4eaa48 100644 --- a/Libraries/LibJS/Interpreter.cpp +++ b/Libraries/LibJS/Interpreter.cpp @@ -158,7 +158,8 @@ void Interpreter::set_variable(const FlyString& name, Value value, bool first_as Optional 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) {