summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Interpreter.h
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-03-22 11:07:55 +0100
committerAndreas Kling <kling@serenityos.org>2020-03-22 13:03:43 +0100
commitcccbe43056748a9443a49abf5bdc938ba5e537d6 (patch)
tree09767cad7e20b1494f8ab23b7c8e31677cbd2970 /Libraries/LibJS/Interpreter.h
parent4f72f6b8866cfa353a29248a4f1ca7c242949231 (diff)
downloadserenity-cccbe43056748a9443a49abf5bdc938ba5e537d6.zip
LibJS: Use FlyString for identifiers
This makes variable and property lookups a lot faster since comparing two FlyStrings is O(1).
Diffstat (limited to 'Libraries/LibJS/Interpreter.h')
-rw-r--r--Libraries/LibJS/Interpreter.h17
1 files changed, 11 insertions, 6 deletions
diff --git a/Libraries/LibJS/Interpreter.h b/Libraries/LibJS/Interpreter.h
index 52962c6d78..4c749fcd0e 100644
--- a/Libraries/LibJS/Interpreter.h
+++ b/Libraries/LibJS/Interpreter.h
@@ -28,6 +28,7 @@
#include <AK/HashMap.h>
#include <AK/String.h>
+#include <AK/FlyString.h>
#include <AK/Vector.h>
#include <LibJS/Forward.h>
#include <LibJS/Heap/Heap.h>
@@ -48,7 +49,7 @@ struct Variable {
struct ScopeFrame {
ScopeType type;
NonnullRefPtr<ScopeNode> scope_node;
- HashMap<String, Variable> variables;
+ HashMap<FlyString, Variable> variables;
};
struct CallFrame {
@@ -57,7 +58,7 @@ struct CallFrame {
};
struct Argument {
- String name;
+ FlyString name;
Value value;
};
@@ -75,9 +76,9 @@ public:
void do_return();
- Value get_variable(const String& name);
- void set_variable(String name, Value, bool first_assignment = false);
- void declare_variable(String name, DeclarationType);
+ Value get_variable(const FlyString& name);
+ void set_variable(const FlyString& name, Value, bool first_assignment = false);
+ void declare_variable(const FlyString& name, DeclarationType);
void gather_roots(Badge<Heap>, HashTable<Cell*>&);
@@ -86,7 +87,11 @@ public:
Value call(Function*, Value this_value, const Vector<Value>& arguments);
- CallFrame& push_call_frame() { m_call_stack.append({ js_undefined(), {} }); return m_call_stack.last(); }
+ CallFrame& push_call_frame()
+ {
+ m_call_stack.append({ js_undefined(), {} });
+ return m_call_stack.last();
+ }
void pop_call_frame() { m_call_stack.take_last(); }
Value this_value() const
{