mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
Update StringId.cs
This commit is contained in:
@@ -4,29 +4,27 @@ namespace TEngine
|
|||||||
{
|
{
|
||||||
public class StringId
|
public class StringId
|
||||||
{
|
{
|
||||||
private static Dictionary<string, int> m_eventTypeHashMap = new Dictionary<string, int>();
|
private static readonly Dictionary<string, int> eventTypeHashMap = new Dictionary<string, int>();
|
||||||
private static Dictionary<int, string> m_eventHashToStringMap = new Dictionary<int, string>();
|
private static readonly Dictionary<int, string> eventHashToStringMap = new Dictionary<int, string>();
|
||||||
private static int m_currentId = 0;
|
private static int _currentId = 0;
|
||||||
|
|
||||||
public static int StringToHash(string val)
|
public static int StringToHash(string val)
|
||||||
{
|
{
|
||||||
int hashId;
|
if (eventTypeHashMap.TryGetValue(val, out var hashId))
|
||||||
if (m_eventTypeHashMap.TryGetValue(val, out hashId))
|
|
||||||
{
|
{
|
||||||
return hashId;
|
return hashId;
|
||||||
}
|
}
|
||||||
|
|
||||||
hashId = ++m_currentId;
|
hashId = ++_currentId;
|
||||||
m_eventTypeHashMap[val] = hashId;
|
eventTypeHashMap[val] = hashId;
|
||||||
m_eventHashToStringMap[hashId] = val;
|
eventHashToStringMap[hashId] = val;
|
||||||
|
|
||||||
return hashId;
|
return hashId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string HashToString(int hash)
|
public static string HashToString(int hash)
|
||||||
{
|
{
|
||||||
string value;
|
if (eventHashToStringMap.TryGetValue(hash, out var value))
|
||||||
if (m_eventHashToStringMap.TryGetValue(hash, out value))
|
|
||||||
{
|
{
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user