예제 #1
0
        private static int GetDeepHashCode(JsonValue value)
        {
            int hash = 0;

            if (value.IsArray)
            {
                foreach (JsonValue child in value.Array)
                {
                    hash ^= ParsePerfTests.GetDeepHashCode(child);
                }
            }
            else if (value.IsObject)
            {
                foreach (KeyValuePair <string, JsonValue> pair in value.Object)
                {
                    hash ^= ParsePerfTests.GetDeepHashCode(pair.Value);
                }
            }
            else if (!value.IsNull)
            {
                hash = value.Value.GetHashCode();
            }

            return(hash);
        }
예제 #2
0
 public void StreamLargeFileSystemTextJson()
 {
     this.StreamFileTestPerf(
         ParsePerfTests.LargeFileName,
         s => System.Text.Json.JsonDocument.Parse(s),
         d => ParsePerfTests.GetDeepHashCode(d.RootElement));
 }
예제 #3
0
        private static int GetDeepHashCode(System.Text.Json.JsonElement value)
        {
            int hash = 0;

            if (value.ValueKind == System.Text.Json.JsonValueKind.Array)
            {
                foreach (System.Text.Json.JsonElement child in value.EnumerateArray())
                {
                    hash ^= ParsePerfTests.GetDeepHashCode(child);
                }
            }
            else if (value.ValueKind == System.Text.Json.JsonValueKind.Object)
            {
                foreach (System.Text.Json.JsonProperty pair in value.EnumerateObject())
                {
                    hash ^= ParsePerfTests.GetDeepHashCode(pair.Value);
                }
            }
            else if (value.ValueKind == System.Text.Json.JsonValueKind.False ||
                     value.ValueKind == System.Text.Json.JsonValueKind.True)
            {
                hash = value.GetBoolean().GetHashCode();
            }
            else if (value.ValueKind == System.Text.Json.JsonValueKind.String)
            {
                hash = value.GetString().GetHashCode();
            }
            else if (value.ValueKind == System.Text.Json.JsonValueKind.Number)
            {
                hash = value.GetDecimal().GetHashCode();
            }

            return(hash);
        }
예제 #4
0
        private static int GetDeepHashCode(JToken value)
        {
            int hash = 0;

            if (value.Type == JTokenType.Array)
            {
                foreach (JToken child in (JArray)value)
                {
                    hash ^= ParsePerfTests.GetDeepHashCode(child);
                }
            }
            else if (value.Type == JTokenType.Object)
            {
                foreach (KeyValuePair <string, JToken> pair in (JObject)value)
                {
                    hash ^= ParsePerfTests.GetDeepHashCode(pair.Value);
                }
            }
            else if (value.Type != JTokenType.Null)
            {
                hash = value.Value <object>().GetHashCode();
            }

            return(hash);
        }
예제 #5
0
 public void StreamLargeFileEfficient()
 {
     this.StreamFileTestPerf(
         ParsePerfTests.LargeFileName,
         s =>
     {
         using (StreamReader reader = new StreamReader(s, detectEncodingFromByteOrderMarks: true))
         {
             return(JsonValue.StringToValue(reader));
         }
     },
         v => ParsePerfTests.GetDeepHashCode(v));
 }
예제 #6
0
        private static int GetDeepHashCode(System.Json.JsonValue value)
        {
            int hash = 0;

            if (value != null)
            {
                if (value.JsonType == System.Json.JsonType.Array)
                {
                    foreach (System.Json.JsonValue child in (System.Json.JsonArray)value)
                    {
                        hash ^= ParsePerfTests.GetDeepHashCode(child);
                    }
                }
                else if (value.JsonType == System.Json.JsonType.Object)
                {
                    foreach (KeyValuePair <string, System.Json.JsonValue> pair in (System.Json.JsonObject)value)
                    {
                        hash ^= ParsePerfTests.GetDeepHashCode(pair.Value);
                    }
                }
                else if (value.JsonType == System.Json.JsonType.Boolean)
                {
                    hash = ((bool)value).GetHashCode();
                }
                else if (value.JsonType == System.Json.JsonType.String)
                {
                    hash = ((string)value).GetHashCode();
                }
                else if (value.JsonType == System.Json.JsonType.Number)
                {
                    hash = ((decimal)value).GetHashCode();
                }
            }

            return(hash);
        }