summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XUtliPoolLib/UniqueString.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-01-25 14:28:30 +0800
committerchai <chaifix@163.com>2021-01-25 14:28:30 +0800
commit6eb915c129fc90c6f4c82ae097dd6ffad5239efc (patch)
tree7dd2be50edf41f36b60fac84696e731c13afe617 /Client/Assets/Scripts/XUtliPoolLib/UniqueString.cs
+scripts
Diffstat (limited to 'Client/Assets/Scripts/XUtliPoolLib/UniqueString.cs')
-rw-r--r--Client/Assets/Scripts/XUtliPoolLib/UniqueString.cs76
1 files changed, 76 insertions, 0 deletions
diff --git a/Client/Assets/Scripts/XUtliPoolLib/UniqueString.cs b/Client/Assets/Scripts/XUtliPoolLib/UniqueString.cs
new file mode 100644
index 00000000..2554df55
--- /dev/null
+++ b/Client/Assets/Scripts/XUtliPoolLib/UniqueString.cs
@@ -0,0 +1,76 @@
+using System;
+using System.Collections.Generic;
+
+namespace XUtliPoolLib
+{
+ public class UniqueString
+ {
+ private static Dictionary<string, string> m_strings = new Dictionary<string, string>();
+
+ public static string Intern(string str, bool removable = true)
+ {
+ bool flag = str == null;
+ string result;
+ if (flag)
+ {
+ result = null;
+ }
+ else
+ {
+ string text = UniqueString.IsInterned(str);
+ bool flag2 = text != null;
+ if (flag2)
+ {
+ result = text;
+ }
+ else if (removable)
+ {
+ UniqueString.m_strings.Add(str, str);
+ result = str;
+ }
+ else
+ {
+ result = string.Intern(str);
+ }
+ }
+ return result;
+ }
+
+ public static string IsInterned(string str)
+ {
+ bool flag = str == null;
+ string result;
+ if (flag)
+ {
+ result = null;
+ }
+ else
+ {
+ string text = string.IsInterned(str);
+ bool flag2 = text != null;
+ if (flag2)
+ {
+ result = text;
+ }
+ else
+ {
+ bool flag3 = UniqueString.m_strings.TryGetValue(str, out text);
+ if (flag3)
+ {
+ result = text;
+ }
+ else
+ {
+ result = null;
+ }
+ }
+ }
+ return result;
+ }
+
+ public static void Clear()
+ {
+ UniqueString.m_strings.Clear();
+ }
+ }
+}