@@ -98,18 +98,14 @@ bool RunJITCommand(lua_State* ls, const char* command)
9898
9999const char * const CScriptEngine::GlobalNamespace = SCRIPT_GLOBAL_NAMESPACE;
100100Lock CScriptEngine::stateMapLock;
101- xr_unordered_map<lua_State*, CScriptEngine*>* CScriptEngine::stateMap = nullptr ;
101+ xr_unordered_map<lua_State*, CScriptEngine*> CScriptEngine::stateMap;
102102
103103string4096 CScriptEngine::g_ca_stdout;
104104
105105void CScriptEngine::reinit ()
106106{
107107 stateMapLock.Enter ();
108- if (!stateMap)
109- {
110- stateMap = new xr_unordered_map<lua_State*, CScriptEngine*>();
111- stateMap->reserve (32 ); // 32 lua states should be enough
112- }
108+ stateMap.reserve (32 ); // 32 lua states should be enough
113109 stateMapLock.Leave ();
114110 if (m_virtual_machine)
115111 {
@@ -1192,12 +1188,9 @@ CScriptEngine* CScriptEngine::GetInstance(lua_State* state)
11921188{
11931189 CScriptEngine* instance = nullptr ;
11941190 stateMapLock.Enter ();
1195- if (stateMap)
1196- {
1197- auto it = stateMap->find (state);
1198- if (it != stateMap->end ())
1199- instance = it->second ;
1200- }
1191+ auto it = stateMap.find (state);
1192+ if (it != stateMap.end ())
1193+ instance = it->second ;
12011194 stateMapLock.Leave ();
12021195 return instance;
12031196}
@@ -1206,14 +1199,11 @@ bool CScriptEngine::RegisterState(lua_State* state, CScriptEngine* scriptEngine)
12061199{
12071200 bool result = false ;
12081201 stateMapLock.Enter ();
1209- if (stateMap)
1202+ auto it = stateMap.find (state);
1203+ if (it == stateMap.end ())
12101204 {
1211- auto it = stateMap->find (state);
1212- if (it == stateMap->end ())
1213- {
1214- stateMap->insert ({state, scriptEngine});
1215- result = true ;
1216- }
1205+ stateMap.insert ({state, scriptEngine});
1206+ result = true ;
12171207 }
12181208 stateMapLock.Leave ();
12191209 return result;
@@ -1225,14 +1215,11 @@ bool CScriptEngine::UnregisterState(lua_State* state)
12251215 return true ;
12261216 bool result = false ;
12271217 stateMapLock.Enter ();
1228- if (stateMap)
1218+ auto it = stateMap.find (state);
1219+ if (it != stateMap.end ())
12291220 {
1230- auto it = stateMap->find (state);
1231- if (it != stateMap->end ())
1232- {
1233- stateMap->erase (it);
1234- result = true ;
1235- }
1221+ stateMap.erase (it);
1222+ result = true ;
12361223 }
12371224 stateMapLock.Leave ();
12381225 return result;
0 commit comments