Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve perf of JsonValue.CreateFromElement by calling ValueKind once #104108

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Serialization;
Expand Down Expand Up @@ -181,18 +180,19 @@ internal static JsonValue CreateFromTypeInfo<T>(T value, JsonTypeInfo<T> jsonTyp

internal static JsonValue? CreateFromElement(ref readonly JsonElement element, JsonNodeOptions? options = null)
{
if (element.ValueKind is JsonValueKind.Null)
switch (element.ValueKind)
{
return null;
}
case JsonValueKind.Null:
return null;

// Force usage of JsonArray and JsonObject instead of supporting those in an JsonValue.
if (element.ValueKind is JsonValueKind.Object or JsonValueKind.Array)
{
ThrowHelper.ThrowInvalidOperationException_NodeElementCannotBeObjectOrArray();
}
case JsonValueKind.Object or JsonValueKind.Array:
// Force usage of JsonArray and JsonObject instead of supporting those in an JsonValue.
ThrowHelper.ThrowInvalidOperationException_NodeElementCannotBeObjectOrArray();
return null;

return new JsonValueOfElement(element, options);
default:
return new JsonValueOfElement(element, options);
}
}
}
}
Loading