1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-22 10:22:52 +01:00

Convert functions to unordered_map and use reserve

This commit is contained in:
Filip Gawin 2018-12-09 15:10:06 +01:00
parent 4063fabe52
commit 84c09d93ce
3 changed files with 10 additions and 5 deletions

View File

@ -1,8 +1,8 @@
#ifndef _LIBRW_RW_FORWARD_HPP_ #ifndef _LIBRW_RW_FORWARD_HPP_
#define _LIBRW_RW_FORWARD_HPP_ #define _LIBRW_RW_FORWARD_HPP_
#include <memory>
#include <unordered_map> #include <unordered_map>
#include <memory>
#include <vector> #include <vector>
// Forward Declarations // Forward Declarations

View File

@ -2,13 +2,12 @@
#define _RWENGINE_SCRIPTMODULE_HPP_ #define _RWENGINE_SCRIPTMODULE_HPP_
#include <cstddef> #include <cstddef>
#include <map> #include <string>
#include <unordered_map>
#include <script/ScriptTypes.hpp> #include <script/ScriptTypes.hpp>
#include "ScriptMachine.hpp" #include "ScriptMachine.hpp"
#include <string>
namespace script_bind { namespace script_bind {
template <class T> template <class T>
struct arg_traits { struct arg_traits {
@ -172,9 +171,13 @@ public:
bool findOpcode(ScriptFunctionID id, ScriptFunctionMeta** out); bool findOpcode(ScriptFunctionID id, ScriptFunctionMeta** out);
void reserveFunctions(size_t nr) {
functions.reserve(nr);
}
private: private:
const std::string name; const std::string name;
std::map<ScriptFunctionID, ScriptFunctionMeta> functions; std::unordered_map<ScriptFunctionID, ScriptFunctionMeta> functions;
}; };
#endif #endif

View File

@ -14,6 +14,8 @@
#include "GTA3ModuleImpl.inl" #include "GTA3ModuleImpl.inl"
GTA3Module::GTA3Module() : ScriptModule("GTA3") { GTA3Module::GTA3Module() : ScriptModule("GTA3") {
reserveFunctions(903);
bind(0x0000, 0, opcode_0000); bind(0x0000, 0, opcode_0000);
bind(0x0001, 1, opcode_0001); bind(0x0001, 1, opcode_0001);
bind(0x0002, 1, opcode_0002); bind(0x0002, 1, opcode_0002);