Skip to content

Commit

Permalink
Fix InlineDictionary Behavior for Single Item Reassignment
Browse files Browse the repository at this point in the history
Previous Behavior:

- When the `Set` method was called, it ignored the `overwrite` parameter if the dictionary contained only one item.
- This caused the `Set` method to behave like the `Add` method, leading to unexpected behavior in composition animations.
- Specifically, the second composition animation would not play because it could not replace the first animation. Instead, it was added after the first animation, preventing it from being executed.

Updated Behavior:

- The `InlineDictionary` now respects the `overwrite` parameter even when it contains only one item.
- This ensures that the second composition animation can overwrite the first one, allowing it to play correctly.
  • Loading branch information
lindexi authored and walterlv committed Nov 6, 2024
1 parent de6e666 commit a9d032b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Avalonia.Base/Utilities/SmallDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,15 @@ void SetCore(TKey key, TValue value, bool overwrite)
}
else
{
// We have a single element, upgrade to array
// We have a single element, check if we should update the value.
if((TKey)_data == key && overwrite)
{
_data = key;
_value = value;

return;
}
// If we do not replace it, upgrade to array.
arr = new KeyValuePair[6];
arr[0] = new KeyValuePair((TKey)_data, _value);
arr[1] = new KeyValuePair(key, value);
Expand Down

0 comments on commit a9d032b

Please sign in to comment.