File tree Expand file tree Collapse file tree 1 file changed +18
-8
lines changed Expand file tree Collapse file tree 1 file changed +18
-8
lines changed Original file line number Diff line number Diff line change 2121#include < string>
2222
2323namespace {
24-
25- opcodetype ParseOpCode (const std::string& s)
24+ class OpCodeParser
2625{
27- static std::map<std::string, opcodetype> mapOpNames;
26+ private:
27+ std::map<std::string, opcodetype> mapOpNames;
2828
29- if (mapOpNames.empty ()) {
30- for (unsigned int op = 0 ; op <= MAX_OPCODE; op++) {
29+ public:
30+ OpCodeParser ()
31+ {
32+ for (unsigned int op = 0 ; op <= MAX_OPCODE; ++op) {
3133 // Allow OP_RESERVED to get into mapOpNames
3234 if (op < OP_NOP && op != OP_RESERVED) {
3335 continue ;
@@ -44,10 +46,18 @@ opcodetype ParseOpCode(const std::string& s)
4446 }
4547 }
4648 }
49+ opcodetype Parse (const std::string& s) const
50+ {
51+ auto it = mapOpNames.find (s);
52+ if (it == mapOpNames.end ()) throw std::runtime_error (" script parse error: unknown opcode" );
53+ return it->second ;
54+ }
55+ };
4756
48- auto it = mapOpNames.find (s);
49- if (it == mapOpNames.end ()) throw std::runtime_error (" script parse error: unknown opcode" );
50- return it->second ;
57+ opcodetype ParseOpCode (const std::string& s)
58+ {
59+ static const OpCodeParser ocp;
60+ return ocp.Parse (s);
5161}
5262
5363} // namespace
You can’t perform that action at this time.
0 commit comments