mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-30 00:31:14 +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
Notes:
sideshowbarker
2024-07-17 16:38:14 +09:00
Author: https://github.com/Lubrsi Commit: https://github.com/SerenityOS/serenity/commit/589c3771e9 Pull-request: https://github.com/SerenityOS/serenity/pull/13312 Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/linusg ✅
|
@ -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…
Reference in a new issue