summaryrefslogtreecommitdiff
path: root/Libraries/LibJS
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-03-21 13:05:43 +0100
committerAndreas Kling <kling@serenityos.org>2020-03-21 13:11:51 +0100
commit00feef86427b7a370ba292f7eca426839ae5699d (patch)
tree20b6b665e5971b9241cb24d0b2b9f117e6b28aba /Libraries/LibJS
parent6c3afca6866023b12c5f9d220cbedccd002bfd60 (diff)
downloadserenity-00feef86427b7a370ba292f7eca426839ae5699d.zip
LibJS: Some optimizations for ObjectExpression
- move() the property map when constructing ObjectExpression instead of making a copy. - Use key+value iterators to traverse the property map in the execute() and dump() functions.
Diffstat (limited to 'Libraries/LibJS')
-rw-r--r--Libraries/LibJS/AST.cpp12
-rw-r--r--Libraries/LibJS/AST.h2
2 files changed, 6 insertions, 8 deletions
diff --git a/Libraries/LibJS/AST.cpp b/Libraries/LibJS/AST.cpp
index 95cb322e74..f6c9847bb3 100644
--- a/Libraries/LibJS/AST.cpp
+++ b/Libraries/LibJS/AST.cpp
@@ -623,10 +623,10 @@ void VariableDeclaration::dump(int indent) const
void ObjectExpression::dump(int indent) const
{
ASTNode::dump(indent);
- for (String property_key : m_properties.keys()) {
+ for (auto it : m_properties) {
print_indent(indent + 1);
- printf("%s: ", property_key.characters());
- m_properties.get(property_key).value()->dump(0);
+ printf("%s: ", it.key.characters());
+ it.value->dump(0);
}
}
@@ -639,10 +639,8 @@ void ExpressionStatement::dump(int indent) const
Value ObjectExpression::execute(Interpreter& interpreter) const
{
auto object = interpreter.heap().allocate<Object>();
- for (String property_key : m_properties.keys()) {
- object->put(property_key, m_properties.get(property_key).value()->execute(interpreter));
- }
-
+ for (auto it : m_properties)
+ object->put(it.key, it.value->execute(interpreter));
return object;
}
diff --git a/Libraries/LibJS/AST.h b/Libraries/LibJS/AST.h
index e8a0039ad8..a1bac10849 100644
--- a/Libraries/LibJS/AST.h
+++ b/Libraries/LibJS/AST.h
@@ -574,7 +574,7 @@ private:
class ObjectExpression : public Expression {
public:
ObjectExpression(HashMap<String, NonnullRefPtr<Expression>> properties = {})
- : m_properties(properties)
+ : m_properties(move(properties))
{
}