Skip to content

Commit 31b8a18

Browse files
[release/9.0] Mitigate JsonObject performance regression. (#108014)
* Mitigate JsonObject and JsonValue performance regressions. * Revert delayed JsonValueKind derivation. --------- Co-authored-by: Eirik Tsarpalis <eirik.tsarpalis@gmail.com>
1 parent 5a90fae commit 31b8a18

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

  • src/libraries/System.Text.Json/src/System/Text/Json/Nodes

src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonObject.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,17 +248,21 @@ internal void SetItem(string propertyName, JsonNode? value)
248248

249249
OrderedDictionary<string, JsonNode?> dict = Dictionary;
250250

251-
if (dict.TryGetValue(propertyName, out JsonNode? replacedValue))
251+
if (!dict.TryAdd(propertyName, value))
252252
{
253+
int index = dict.IndexOf(propertyName);
254+
Debug.Assert(index >= 0);
255+
JsonNode? replacedValue = dict.GetAt(index).Value;
256+
253257
if (ReferenceEquals(value, replacedValue))
254258
{
255259
return;
256260
}
257261

258262
DetachParent(replacedValue);
263+
dict.SetAt(index, value);
259264
}
260265

261-
dict[propertyName] = value;
262266
value?.AssignParent(this);
263267
}
264268

0 commit comments

Comments
 (0)