File tree Expand file tree Collapse file tree 1 file changed +8
-0
lines changed
Userland/Libraries/LibJS/Bytecode Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -269,6 +269,14 @@ Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> LogicalExpression::gene
269
269
Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> UnaryExpression::generate_bytecode (Bytecode::Generator& generator, Optional<ScopedOperand> preferred_dst) const
270
270
{
271
271
Bytecode::Generator::SourceLocationScope scope (generator, *this );
272
+
273
+ // OPTIMIZATION: Turn expressions like `-1` into a constant.
274
+ if (m_op == UnaryOp::Minus && is<NumericLiteral>(*m_lhs)) {
275
+ auto & numeric_literal = static_cast <NumericLiteral const &>(*m_lhs);
276
+ auto value = numeric_literal.value ();
277
+ return generator.add_constant (Value (-value.as_double ()));
278
+ }
279
+
272
280
if (m_op == UnaryOp::Delete)
273
281
return generator.emit_delete_reference (m_lhs);
274
282
You can’t perform that action at this time.
0 commit comments