Skip to content

Commit

Permalink
Upgrade std hash structures
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Jan 6, 2018
1 parent 3cf0474 commit 6306bda
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 17 deletions.
11 changes: 2 additions & 9 deletions src/xrCommon/xr_unordered_map.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
#pragma once
// XXX: upgrade std hash structures
#ifndef _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS
#define _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS
#endif
#include <hash_map>
#include <unordered_map>
#include "xrCore/Memory/XRayAllocator.hpp"

template <typename K, class V, class _Traits = stdext::hash_compare<K, std::less<K>>, typename allocator = XRay::xray_allocator<std::pair<K, V>>>
using xr_hash_map = stdext::hash_map<K, V, _Traits, allocator>;

template<class Key, class T, class Hasher = std::hash<Key>, class KeyEqual = std::equal_to<Key>, class allocator = XRay::xray_allocator<std::pair<const Key, T>>>
template <class Key, class T, class Hasher = std::hash<Key>, class KeyEqual = std::equal_to<Key>,
class allocator = XRay::xray_allocator<std::pair<const Key, T>>>
using xr_unordered_map = std::unordered_map<Key, T, Hasher, KeyEqual, allocator>;
2 changes: 0 additions & 2 deletions src/xrCore/xrCore.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#pragma once

// XXX: upgrade std hash structures
#define _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS
#ifndef DEBUG
#define MASTER_GOLD
#endif // DEBUG
Expand Down
6 changes: 3 additions & 3 deletions src/xrGame/xrServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@

class CSE_Abstract;

const u32 NET_Latency = 50; // time in (ms)
constexpr u32 NET_Latency = 50; // time in (ms)

// t-defs
typedef xr_hash_map<u16, CSE_Abstract*> xrS_entities;
// XXX: check if u16 used for entity's id. If true, then this must be changed, if we want to increase the number of ID's.
using xrS_entities = xr_unordered_map<u16, CSE_Abstract*>;

class xrClientData : public IClient
{
Expand Down
4 changes: 2 additions & 2 deletions src/xrScriptEngine/script_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ bool RunJITCommand(lua_State* ls, const char* command)

const char* const CScriptEngine::GlobalNamespace = SCRIPT_GLOBAL_NAMESPACE;
Lock CScriptEngine::stateMapLock;
xr_hash_map<lua_State*, CScriptEngine*>* CScriptEngine::stateMap = nullptr;
xr_unordered_map<lua_State*, CScriptEngine*>* CScriptEngine::stateMap = nullptr;

string4096 CScriptEngine::g_ca_stdout;

Expand All @@ -119,7 +119,7 @@ void CScriptEngine::reinit()
stateMapLock.Enter();
if (!stateMap)
{
stateMap = new xr_hash_map<lua_State*, CScriptEngine*>();
stateMap = new xr_unordered_map<lua_State*, CScriptEngine*>();
stateMap->reserve(32); // 32 lua states should be enough
}
stateMapLock.Leave();
Expand Down
2 changes: 1 addition & 1 deletion src/xrScriptEngine/script_engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class XRSCRIPTENGINE_API CScriptEngine

private:
static Lock stateMapLock;
static xr_hash_map<lua_State*, CScriptEngine*>* stateMap;
static xr_unordered_map<lua_State*, CScriptEngine*>* stateMap;
lua_State* m_virtual_machine;
CScriptThread* m_current_thread;
bool m_reload_modules;
Expand Down

0 comments on commit 6306bda

Please sign in to comment.