mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-10 13:00:29 +03:00
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.
This commit is contained in:
parent
6c3afca686
commit
00feef8642
Notes:
sideshowbarker
2024-07-19 08:12:22 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/00feef86427
@ -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;
|
||||
}
|
||||
|
||||
|
@ -574,7 +574,7 @@ private:
|
||||
class ObjectExpression : public Expression {
|
||||
public:
|
||||
ObjectExpression(HashMap<String, NonnullRefPtr<Expression>> properties = {})
|
||||
: m_properties(properties)
|
||||
: m_properties(move(properties))
|
||||
{
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user