Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdaadf8e

Browse files
Improve perf of JsonValue.CreateFromElement by calling ValueKind once (#104108)
* Improve perf of JsonValue.CreateFromElement by calling JsonElement.ValueKind only once* Use switch statement instead of multiple ifs* Update src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonValue.cs* Update src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonValue.cs---------Co-authored-by: Eirik Tsarpalis <eirik.tsarpalis@gmail.com>
1 parentf8bcb89 commitdaadf8e

File tree

1 file changed

+10
-10
lines changed
  • src/libraries/System.Text.Json/src/System/Text/Json/Nodes

1 file changed

+10
-10
lines changed

‎src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonValue.cs‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
usingSystem.Collections.Generic;
54
usingSystem.Diagnostics;
65
usingSystem.Diagnostics.CodeAnalysis;
76
usingSystem.Text.Json.Serialization;
@@ -181,18 +180,19 @@ internal static JsonValue CreateFromTypeInfo<T>(T value, JsonTypeInfo<T> jsonTyp
181180

182181
internalstaticJsonValue?CreateFromElement(refreadonlyJsonElementelement,JsonNodeOptions?options=null)
183182
{
184-
if(element.ValueKindisJsonValueKind.Null)
183+
switch(element.ValueKind)
185184
{
186-
returnnull;
187-
}
185+
caseJsonValueKind.Null:
186+
returnnull;
188187

189-
// Force usage of JsonArray and JsonObject instead of supporting those in an JsonValue.
190-
if(element.ValueKindisJsonValueKind.Object orJsonValueKind.Array)
191-
{
192-
ThrowHelper.ThrowInvalidOperationException_NodeElementCannotBeObjectOrArray();
193-
}
188+
caseJsonValueKind.Object orJsonValueKind.Array:
189+
// Force usage of JsonArray and JsonObject instead of supporting those in an JsonValue.
190+
ThrowHelper.ThrowInvalidOperationException_NodeElementCannotBeObjectOrArray();
191+
returnnull;
194192

195-
returnnewJsonValueOfElement(element,options);
193+
default:
194+
returnnewJsonValueOfElement(element,options);
195+
}
196196
}
197197
}
198198
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp