Skip to content

Commit

Permalink
[release/9.0] Mitigate JsonObject performance regression. (#108014)
Browse files Browse the repository at this point in the history
* Mitigate JsonObject and JsonValue performance regressions.

* Revert delayed JsonValueKind derivation.

---------

Co-authored-by: Eirik Tsarpalis <eirik.tsarpalis@gmail.com>
  • Loading branch information
github-actions[bot] and eiriktsarpalis authored Sep 19, 2024
1 parent 5a90fae commit 31b8a18
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -248,17 +248,21 @@ internal void SetItem(string propertyName, JsonNode? value)

OrderedDictionary<string, JsonNode?> dict = Dictionary;

if (dict.TryGetValue(propertyName, out JsonNode? replacedValue))
if (!dict.TryAdd(propertyName, value))
{
int index = dict.IndexOf(propertyName);
Debug.Assert(index >= 0);
JsonNode? replacedValue = dict.GetAt(index).Value;

if (ReferenceEquals(value, replacedValue))
{
return;
}

DetachParent(replacedValue);
dict.SetAt(index, value);
}

dict[propertyName] = value;
value?.AssignParent(this);
}

Expand Down

0 comments on commit 31b8a18

Please sign in to comment.