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 21
21
#include < string>
22
22
23
23
namespace {
24
-
25
- opcodetype ParseOpCode (const std::string& s)
24
+ class OpCodeParser
26
25
{
27
- static std::map<std::string, opcodetype> mapOpNames;
26
+ private:
27
+ std::map<std::string, opcodetype> mapOpNames;
28
28
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) {
31
33
// Allow OP_RESERVED to get into mapOpNames
32
34
if (op < OP_NOP && op != OP_RESERVED) {
33
35
continue ;
@@ -44,10 +46,18 @@ opcodetype ParseOpCode(const std::string& s)
44
46
}
45
47
}
46
48
}
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
+ };
47
56
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);
51
61
}
52
62
53
63
} // namespace
You can’t perform that action at this time.
0 commit comments