Skip to content

Commit

Permalink
Mitigate JsonObject performance regression. (#107944)
Browse files Browse the repository at this point in the history
* Mitigate JsonObject and JsonValue performance regressions.

* Revert delayed JsonValueKind derivation.
  • Loading branch information
eiriktsarpalis authored Sep 19, 2024
1 parent 3bb186e commit e8613a6
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 e8613a6

Please sign in to comment.