mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:18:13 +00:00
LibJS: Only store MemberExpression object when loading a computed prop
When calling emit_load_from_reference with a MemberExpression, it is only necessary to store the result of evaluating MemberExpression's object when performing computed property lookup. This allows us to skip unnecessary stores for identifier lookup. For example, this would generate 3 unnecessary stores: ``` > Temporal.PlainDateTime.prototype.add JS::Bytecode::Executable (REPL) 1: [ 0] GetVariable 0 (Temporal) [ 28] Store $2 [ 30] GetById 1 (PlainDateTime) [ 40] Store $3 [ 48] GetById 2 (prototype) [ 58] Store $4 [ 60] GetById 3 (add) ``` With this, it generates: ``` > Temporal.PlainDateTime.prototype.add JS::Bytecode::Executable (REPL) 1: [ 0] GetVariable 0 (Temporal) [ 28] GetById 1 (PlainDateTime) [ 38] GetById 2 (prototype) [ 48] GetById 3 (add) ```
This commit is contained in:
parent
88901182b8
commit
589c3771e9
1 changed files with 3 additions and 3 deletions
|
@ -137,10 +137,10 @@ CodeGenerationErrorOr<void> Generator::emit_load_from_reference(JS::ASTNode cons
|
|||
auto& expression = static_cast<MemberExpression const&>(node);
|
||||
TRY(expression.object().generate_bytecode(*this));
|
||||
|
||||
auto object_reg = allocate_register();
|
||||
emit<Bytecode::Op::Store>(object_reg);
|
||||
|
||||
if (expression.is_computed()) {
|
||||
auto object_reg = allocate_register();
|
||||
emit<Bytecode::Op::Store>(object_reg);
|
||||
|
||||
TRY(expression.property().generate_bytecode(*this));
|
||||
emit<Bytecode::Op::GetByValue>(object_reg);
|
||||
} else if (expression.property().is_identifier()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue