mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 09:27:35 +00:00
LibJS: Instantiate primitive array expressions using a single operation
This will not meaningfully affect short array literals, but it does give us a bit of extra perf when evaluating huge array expressions like in Kraken/imaging-darkroom.js
This commit is contained in:
parent
5e3a799e97
commit
f19349e1b6
7 changed files with 92 additions and 6 deletions
|
@ -1133,10 +1133,21 @@ private:
|
|||
Vector<NonnullRefPtr<Expression const>> m_expressions;
|
||||
};
|
||||
|
||||
class BooleanLiteral final : public Expression {
|
||||
class PrimitiveLiteral : public Expression {
|
||||
public:
|
||||
virtual Value value() const = 0;
|
||||
|
||||
protected:
|
||||
explicit PrimitiveLiteral(SourceRange source_range)
|
||||
: Expression(move(source_range))
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
class BooleanLiteral final : public PrimitiveLiteral {
|
||||
public:
|
||||
explicit BooleanLiteral(SourceRange source_range, bool value)
|
||||
: Expression(move(source_range))
|
||||
: PrimitiveLiteral(move(source_range))
|
||||
, m_value(value)
|
||||
{
|
||||
}
|
||||
|
@ -1144,14 +1155,16 @@ public:
|
|||
virtual void dump(int indent) const override;
|
||||
virtual Bytecode::CodeGenerationErrorOr<void> generate_bytecode(Bytecode::Generator&) const override;
|
||||
|
||||
virtual Value value() const override { return Value(m_value); }
|
||||
|
||||
private:
|
||||
bool m_value { false };
|
||||
};
|
||||
|
||||
class NumericLiteral final : public Expression {
|
||||
class NumericLiteral final : public PrimitiveLiteral {
|
||||
public:
|
||||
explicit NumericLiteral(SourceRange source_range, double value)
|
||||
: Expression(move(source_range))
|
||||
: PrimitiveLiteral(move(source_range))
|
||||
, m_value(value)
|
||||
{
|
||||
}
|
||||
|
@ -1159,6 +1172,8 @@ public:
|
|||
virtual void dump(int indent) const override;
|
||||
virtual Bytecode::CodeGenerationErrorOr<void> generate_bytecode(Bytecode::Generator&) const override;
|
||||
|
||||
virtual Value value() const override { return m_value; }
|
||||
|
||||
private:
|
||||
Value m_value;
|
||||
};
|
||||
|
@ -1197,15 +1212,17 @@ private:
|
|||
DeprecatedString m_value;
|
||||
};
|
||||
|
||||
class NullLiteral final : public Expression {
|
||||
class NullLiteral final : public PrimitiveLiteral {
|
||||
public:
|
||||
explicit NullLiteral(SourceRange source_range)
|
||||
: Expression(move(source_range))
|
||||
: PrimitiveLiteral(move(source_range))
|
||||
{
|
||||
}
|
||||
|
||||
virtual void dump(int indent) const override;
|
||||
virtual Bytecode::CodeGenerationErrorOr<void> generate_bytecode(Bytecode::Generator&) const override;
|
||||
|
||||
virtual Value value() const override { return js_null(); }
|
||||
};
|
||||
|
||||
class RegExpLiteral final : public Expression {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue