Browse Source

threadsafe JSONParser

pull/123/head
notgiven688 3 years ago
parent
commit
cd01c89f07
1 changed files with 19 additions and 20 deletions
  1. +19
    -20
      server/Server/JSONParser.cs

+ 19
- 20
server/Server/JSONParser.cs View File

@ -33,36 +33,35 @@ namespace TinyJson {
public static class JSONParser {
[ThreadStatic]
static Stack<List<string>> splitArrayPool;
[ThreadStatic]
static Stack<List<string>> splitArrayPool;
[ThreadStatic]
static StringBuilder stringBuilder;
[ThreadStatic]
static StringBuilder stringBuilder;
[ThreadStatic]
static Dictionary<Type, Dictionary<string, FieldInfo>> fieldInfoCache;
[ThreadStatic]
static Dictionary<Type, Dictionary<string, FieldInfo>> fieldInfoCache;
[ThreadStatic]
static Dictionary<Type, Dictionary<string, PropertyInfo>> propertyInfoCache;
[ThreadStatic]
static Dictionary<Type, Dictionary<string, PropertyInfo>> propertyInfoCache;
[ThreadStatic]
static bool initialized = false;
[ThreadStatic]
static bool initialized = false;
public static T FromJson<T> (this string json) {
if (!initialized) {
if (!initialized) {
/* Do not specify initial values for fields marked with ThreadStaticAttribute, because such initialization
* occurs only once, when the class constructor executes, and therefore affects only one thread. */
/* Do not specify initial values for fields marked with ThreadStaticAttribute, because such initialization
* occurs only once, when the class constructor executes, and therefore affects only one thread. */
splitArrayPool = new Stack<List<string>> ();
stringBuilder = new StringBuilder ();
fieldInfoCache = new Dictionary<Type, Dictionary<string, FieldInfo>> ();
propertyInfoCache = new Dictionary<Type, Dictionary<string, PropertyInfo>> ();
initialized = true;
}
splitArrayPool = new Stack<List<string>> ();
stringBuilder = new StringBuilder ();
fieldInfoCache = new Dictionary<Type, Dictionary<string, FieldInfo>> ();
propertyInfoCache = new Dictionary<Type, Dictionary<string, PropertyInfo>> ();
initialized = true;
}
try {
if (string.IsNullOrEmpty (json))

Loading…
Cancel
Save