mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:57:35 +00:00
LibRegex: Avoid initialization checks in get_opcode_by_id()
This commit is contained in:
parent
794dc368f1
commit
d3c2a3caea
2 changed files with 67 additions and 127 deletions
|
@ -129,7 +129,11 @@ class OpCode;
|
|||
|
||||
class ByteCode : public Vector<ByteCodeValueType> {
|
||||
public:
|
||||
ByteCode() = default;
|
||||
ByteCode()
|
||||
{
|
||||
ensure_opcodes_initialized();
|
||||
}
|
||||
|
||||
ByteCode(const ByteCode&) = default;
|
||||
virtual ~ByteCode() = default;
|
||||
|
||||
|
@ -449,6 +453,7 @@ private:
|
|||
empend((ByteCodeValueType)view[i]);
|
||||
}
|
||||
|
||||
void ensure_opcodes_initialized();
|
||||
ALWAYS_INLINE OpCode& get_opcode_by_id(OpCodeId id) const;
|
||||
static OwnPtr<OpCode> s_opcodes[(size_t)OpCodeId::Last + 1];
|
||||
static bool s_opcodes_initialized;
|
||||
|
@ -476,11 +481,7 @@ const char* execution_result_name(ExecutionResult result);
|
|||
|
||||
class OpCode {
|
||||
public:
|
||||
OpCode(ByteCode& bytecode)
|
||||
: m_bytecode(&bytecode)
|
||||
{
|
||||
}
|
||||
|
||||
OpCode() = default;
|
||||
virtual ~OpCode() = default;
|
||||
|
||||
virtual OpCodeId opcode_id() const = 0;
|
||||
|
@ -518,16 +519,12 @@ public:
|
|||
ALWAYS_INLINE const ByteCode& bytecode() const { return *m_bytecode; }
|
||||
|
||||
protected:
|
||||
ByteCode* m_bytecode;
|
||||
ByteCode* m_bytecode { nullptr };
|
||||
Optional<MatchState*> m_state;
|
||||
};
|
||||
|
||||
class OpCode_Exit final : public OpCode {
|
||||
public:
|
||||
OpCode_Exit(ByteCode& bytecode)
|
||||
: OpCode(bytecode)
|
||||
{
|
||||
}
|
||||
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
||||
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::Exit; }
|
||||
ALWAYS_INLINE size_t size() const override { return 1; }
|
||||
|
@ -536,10 +533,6 @@ public:
|
|||
|
||||
class OpCode_FailForks final : public OpCode {
|
||||
public:
|
||||
OpCode_FailForks(ByteCode& bytecode)
|
||||
: OpCode(bytecode)
|
||||
{
|
||||
}
|
||||
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
||||
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::FailForks; }
|
||||
ALWAYS_INLINE size_t size() const override { return 2; }
|
||||
|
@ -549,10 +542,6 @@ public:
|
|||
|
||||
class OpCode_Save final : public OpCode {
|
||||
public:
|
||||
OpCode_Save(ByteCode& bytecode)
|
||||
: OpCode(bytecode)
|
||||
{
|
||||
}
|
||||
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
||||
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::Save; }
|
||||
ALWAYS_INLINE size_t size() const override { return 1; }
|
||||
|
@ -561,10 +550,6 @@ public:
|
|||
|
||||
class OpCode_Restore final : public OpCode {
|
||||
public:
|
||||
OpCode_Restore(ByteCode& bytecode)
|
||||
: OpCode(bytecode)
|
||||
{
|
||||
}
|
||||
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
||||
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::Restore; }
|
||||
ALWAYS_INLINE size_t size() const override { return 1; }
|
||||
|
@ -573,10 +558,6 @@ public:
|
|||
|
||||
class OpCode_GoBack final : public OpCode {
|
||||
public:
|
||||
OpCode_GoBack(ByteCode& bytecode)
|
||||
: OpCode(bytecode)
|
||||
{
|
||||
}
|
||||
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
||||
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::GoBack; }
|
||||
ALWAYS_INLINE size_t size() const override { return 2; }
|
||||
|
@ -586,10 +567,6 @@ public:
|
|||
|
||||
class OpCode_Jump final : public OpCode {
|
||||
public:
|
||||
OpCode_Jump(ByteCode& bytecode)
|
||||
: OpCode(bytecode)
|
||||
{
|
||||
}
|
||||
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
||||
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::Jump; }
|
||||
ALWAYS_INLINE size_t size() const override { return 2; }
|
||||
|
@ -602,10 +579,6 @@ public:
|
|||
|
||||
class OpCode_ForkJump final : public OpCode {
|
||||
public:
|
||||
OpCode_ForkJump(ByteCode& bytecode)
|
||||
: OpCode(bytecode)
|
||||
{
|
||||
}
|
||||
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
||||
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::ForkJump; }
|
||||
ALWAYS_INLINE size_t size() const override { return 2; }
|
||||
|
@ -618,10 +591,6 @@ public:
|
|||
|
||||
class OpCode_ForkStay final : public OpCode {
|
||||
public:
|
||||
OpCode_ForkStay(ByteCode& bytecode)
|
||||
: OpCode(bytecode)
|
||||
{
|
||||
}
|
||||
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
||||
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::ForkStay; }
|
||||
ALWAYS_INLINE size_t size() const override { return 2; }
|
||||
|
@ -634,10 +603,6 @@ public:
|
|||
|
||||
class OpCode_CheckBegin final : public OpCode {
|
||||
public:
|
||||
OpCode_CheckBegin(ByteCode& bytecode)
|
||||
: OpCode(bytecode)
|
||||
{
|
||||
}
|
||||
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
||||
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::CheckBegin; }
|
||||
ALWAYS_INLINE size_t size() const override { return 1; }
|
||||
|
@ -646,10 +611,6 @@ public:
|
|||
|
||||
class OpCode_CheckEnd final : public OpCode {
|
||||
public:
|
||||
OpCode_CheckEnd(ByteCode& bytecode)
|
||||
: OpCode(bytecode)
|
||||
{
|
||||
}
|
||||
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
||||
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::CheckEnd; }
|
||||
ALWAYS_INLINE size_t size() const override { return 1; }
|
||||
|
@ -658,10 +619,6 @@ public:
|
|||
|
||||
class OpCode_CheckBoundary final : public OpCode {
|
||||
public:
|
||||
OpCode_CheckBoundary(ByteCode& bytecode)
|
||||
: OpCode(bytecode)
|
||||
{
|
||||
}
|
||||
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
||||
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::CheckBoundary; }
|
||||
ALWAYS_INLINE size_t size() const override { return 2; }
|
||||
|
@ -672,10 +629,6 @@ public:
|
|||
|
||||
class OpCode_SaveLeftCaptureGroup final : public OpCode {
|
||||
public:
|
||||
OpCode_SaveLeftCaptureGroup(ByteCode& bytecode)
|
||||
: OpCode(bytecode)
|
||||
{
|
||||
}
|
||||
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
||||
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::SaveLeftCaptureGroup; }
|
||||
ALWAYS_INLINE size_t size() const override { return 2; }
|
||||
|
@ -685,10 +638,6 @@ public:
|
|||
|
||||
class OpCode_SaveRightCaptureGroup final : public OpCode {
|
||||
public:
|
||||
OpCode_SaveRightCaptureGroup(ByteCode& bytecode)
|
||||
: OpCode(bytecode)
|
||||
{
|
||||
}
|
||||
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
||||
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::SaveRightCaptureGroup; }
|
||||
ALWAYS_INLINE size_t size() const override { return 2; }
|
||||
|
@ -698,10 +647,6 @@ public:
|
|||
|
||||
class OpCode_SaveLeftNamedCaptureGroup final : public OpCode {
|
||||
public:
|
||||
OpCode_SaveLeftNamedCaptureGroup(ByteCode& bytecode)
|
||||
: OpCode(bytecode)
|
||||
{
|
||||
}
|
||||
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
||||
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::SaveLeftNamedCaptureGroup; }
|
||||
ALWAYS_INLINE size_t size() const override { return 3; }
|
||||
|
@ -715,10 +660,6 @@ public:
|
|||
|
||||
class OpCode_SaveRightNamedCaptureGroup final : public OpCode {
|
||||
public:
|
||||
OpCode_SaveRightNamedCaptureGroup(ByteCode& bytecode)
|
||||
: OpCode(bytecode)
|
||||
{
|
||||
}
|
||||
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
||||
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::SaveRightNamedCaptureGroup; }
|
||||
ALWAYS_INLINE size_t size() const override { return 3; }
|
||||
|
@ -732,10 +673,6 @@ public:
|
|||
|
||||
class OpCode_Compare final : public OpCode {
|
||||
public:
|
||||
OpCode_Compare(ByteCode& bytecode)
|
||||
: OpCode(bytecode)
|
||||
{
|
||||
}
|
||||
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
||||
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::Compare; }
|
||||
ALWAYS_INLINE size_t size() const override { return arguments_size() + 3; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue