Browse Source

remove some duplicate dict lookups (#19138)

pull/19147/head
Simon Cropp 1 year ago
committed by GitHub
parent
commit
5fa1e7f717
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 3
      src/Avalonia.Base/Collections/AvaloniaDictionary.cs
  2. 3
      src/Avalonia.Base/Controls/NameScope.cs
  3. 3
      src/Avalonia.Base/Media/MediaContext.cs
  4. 3
      src/Avalonia.Base/Utilities/SmallDictionary.cs

3
src/Avalonia.Base/Collections/AvaloniaDictionary.cs

@ -167,9 +167,8 @@ namespace Avalonia.Collections
/// <inheritdoc/>
public bool Remove(TKey key)
{
if (_inner.TryGetValue(key, out var value))
if (_inner.Remove(key, out var value))
{
_inner.Remove(key);
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Count)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs($"{CommonPropertyNames.IndexerName}[{key}]"));

3
src/Avalonia.Base/Controls/NameScope.cs

@ -68,9 +68,8 @@ namespace Avalonia.Controls
else
{
_inner.Add(name, element);
if (_pendingSearches.TryGetValue(name, out var tcs))
if (_pendingSearches.Remove(name, out var tcs))
{
_pendingSearches.Remove(name);
tcs.SetResult(element);
}
}

3
src/Avalonia.Base/Media/MediaContext.cs

@ -173,9 +173,8 @@ internal partial class MediaContext : ICompositorScheduler
public void RemoveTopLevel(object key)
{
if (_topLevels.TryGetValue(key, out var info))
if (_topLevels.Remove(key, out var info))
{
_topLevels.Remove(key);
info.Renderer.Stop();
}
}

3
src/Avalonia.Base/Utilities/SmallDictionary.cs

@ -292,9 +292,8 @@ internal struct InlineDictionary<TKey, TValue> : IEnumerable<KeyValuePair<TKey,
}
else if (_data is Dictionary<TKey, TValue?> dic)
{
if (!dic.TryGetValue(key, out value))
if (!dic.Remove(key, out value))
return false;
dic.Remove(key);
}
value = default;

Loading…
Cancel
Save