summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorGunnar Beutner <gbeutner@serenityos.org>2021-06-13 22:10:25 +0200
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2021-06-14 16:09:58 +0430
commit1fb4471506f654be5354c9194b8a99304c6f7cc0 (patch)
tree12506a01f3af2e064ee85a206008de8e536f36e9 /Userland
parentc38f051bf7a1b8846dce9314c0105a8558175938 (diff)
downloadserenity-1fb4471506f654be5354c9194b8a99304c6f7cc0.zip
LibRegex: Use a plain array to store opcodes
Using a hash map is unnecessary because the number of opcodes and their IDs never change.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibRegex/RegexByteCode.cpp40
-rw-r--r--Userland/Libraries/LibRegex/RegexByteCode.h3
2 files changed, 23 insertions, 20 deletions
diff --git a/Userland/Libraries/LibRegex/RegexByteCode.cpp b/Userland/Libraries/LibRegex/RegexByteCode.cpp
index d508851ab0..7ac1cb97c5 100644
--- a/Userland/Libraries/LibRegex/RegexByteCode.cpp
+++ b/Userland/Libraries/LibRegex/RegexByteCode.cpp
@@ -87,69 +87,71 @@ static const char* character_class_name(CharClass ch_class)
}
}
-HashMap<u32, OwnPtr<OpCode>> ByteCode::s_opcodes {};
+OwnPtr<OpCode> ByteCode::s_opcodes[(size_t)OpCodeId::Last + 1];
+bool ByteCode::s_opcodes_initialized { false };
ALWAYS_INLINE OpCode* ByteCode::get_opcode_by_id(OpCodeId id) const
{
- if (!s_opcodes.size()) {
+ if (!s_opcodes_initialized) {
for (u32 i = (u32)OpCodeId::First; i <= (u32)OpCodeId::Last; ++i) {
switch ((OpCodeId)i) {
case OpCodeId::Exit:
- s_opcodes.set(i, make<OpCode_Exit>(*const_cast<ByteCode*>(this)));
+ s_opcodes[i] = make<OpCode_Exit>(*const_cast<ByteCode*>(this));
break;
case OpCodeId::Jump:
- s_opcodes.set(i, make<OpCode_Jump>(*const_cast<ByteCode*>(this)));
+ s_opcodes[i] = make<OpCode_Jump>(*const_cast<ByteCode*>(this));
break;
case OpCodeId::Compare:
- s_opcodes.set(i, make<OpCode_Compare>(*const_cast<ByteCode*>(this)));
+ s_opcodes[i] = make<OpCode_Compare>(*const_cast<ByteCode*>(this));
break;
case OpCodeId::CheckEnd:
- s_opcodes.set(i, make<OpCode_CheckEnd>(*const_cast<ByteCode*>(this)));
+ s_opcodes[i] = make<OpCode_CheckEnd>(*const_cast<ByteCode*>(this));
break;
case OpCodeId::CheckBoundary:
- s_opcodes.set(i, make<OpCode_CheckBoundary>(*const_cast<ByteCode*>(this)));
+ s_opcodes[i] = make<OpCode_CheckBoundary>(*const_cast<ByteCode*>(this));
break;
case OpCodeId::ForkJump:
- s_opcodes.set(i, make<OpCode_ForkJump>(*const_cast<ByteCode*>(this)));
+ s_opcodes[i] = make<OpCode_ForkJump>(*const_cast<ByteCode*>(this));
break;
case OpCodeId::ForkStay:
- s_opcodes.set(i, make<OpCode_ForkStay>(*const_cast<ByteCode*>(this)));
+ s_opcodes[i] = make<OpCode_ForkStay>(*const_cast<ByteCode*>(this));
break;
case OpCodeId::FailForks:
- s_opcodes.set(i, make<OpCode_FailForks>(*const_cast<ByteCode*>(this)));
+ s_opcodes[i] = make<OpCode_FailForks>(*const_cast<ByteCode*>(this));
break;
case OpCodeId::Save:
- s_opcodes.set(i, make<OpCode_Save>(*const_cast<ByteCode*>(this)));
+ s_opcodes[i] = make<OpCode_Save>(*const_cast<ByteCode*>(this));
break;
case OpCodeId::Restore:
- s_opcodes.set(i, make<OpCode_Restore>(*const_cast<ByteCode*>(this)));
+ s_opcodes[i] = make<OpCode_Restore>(*const_cast<ByteCode*>(this));
break;
case OpCodeId::GoBack:
- s_opcodes.set(i, make<OpCode_GoBack>(*const_cast<ByteCode*>(this)));
+ s_opcodes[i] = make<OpCode_GoBack>(*const_cast<ByteCode*>(this));
break;
case OpCodeId::CheckBegin:
- s_opcodes.set(i, make<OpCode_CheckBegin>(*const_cast<ByteCode*>(this)));
+ s_opcodes[i] = make<OpCode_CheckBegin>(*const_cast<ByteCode*>(this));
break;
case OpCodeId::SaveLeftCaptureGroup:
- s_opcodes.set(i, make<OpCode_SaveLeftCaptureGroup>(*const_cast<ByteCode*>(this)));
+ s_opcodes[i] = make<OpCode_SaveLeftCaptureGroup>(*const_cast<ByteCode*>(this));
break;
case OpCodeId::SaveRightCaptureGroup:
- s_opcodes.set(i, make<OpCode_SaveRightCaptureGroup>(*const_cast<ByteCode*>(this)));
+ s_opcodes[i] = make<OpCode_SaveRightCaptureGroup>(*const_cast<ByteCode*>(this));
break;
case OpCodeId::SaveLeftNamedCaptureGroup:
- s_opcodes.set(i, make<OpCode_SaveLeftNamedCaptureGroup>(*const_cast<ByteCode*>(this)));
+ s_opcodes[i] = make<OpCode_SaveLeftNamedCaptureGroup>(*const_cast<ByteCode*>(this));
break;
case OpCodeId::SaveRightNamedCaptureGroup:
- s_opcodes.set(i, make<OpCode_SaveRightNamedCaptureGroup>(*const_cast<ByteCode*>(this)));
+ s_opcodes[i] = make<OpCode_SaveRightNamedCaptureGroup>(*const_cast<ByteCode*>(this));
break;
}
}
+ s_opcodes_initialized = true;
}
if (id > OpCodeId::Last)
return nullptr;
- return const_cast<OpCode*>(s_opcodes.get((u32)id).value())->set_bytecode(*const_cast<ByteCode*>(this));
+ return const_cast<OpCode*>(s_opcodes[(u32)id]->set_bytecode(*const_cast<ByteCode*>(this)));
}
OpCode* ByteCode::get_opcode(MatchState& state) const
diff --git a/Userland/Libraries/LibRegex/RegexByteCode.h b/Userland/Libraries/LibRegex/RegexByteCode.h
index fbb2726c46..4bd3a4dfc4 100644
--- a/Userland/Libraries/LibRegex/RegexByteCode.h
+++ b/Userland/Libraries/LibRegex/RegexByteCode.h
@@ -450,7 +450,8 @@ private:
}
ALWAYS_INLINE OpCode* get_opcode_by_id(OpCodeId id) const;
- static HashMap<u32, OwnPtr<OpCode>> s_opcodes;
+ static OwnPtr<OpCode> s_opcodes[(size_t)OpCodeId::Last + 1];
+ static bool s_opcodes_initialized;
};
#define ENUMERATE_EXECUTION_RESULTS \