From 5cbe89e9d6d6ba51acfb4aa7b3881f2f8158119b Mon Sep 17 00:00:00 2001 From: mstr2 Date: Wed, 16 Jan 2019 20:01:38 +0100 Subject: [PATCH] Switched AvaloniaPropertyRegistry._properties from Dictionary to List --- src/Avalonia.Base/AvaloniaProperty.cs | 2 +- src/Avalonia.Base/AvaloniaPropertyRegistry.cs | 10 ++-- src/Avalonia.Base/ValueStore.cs | 47 ++++++++----------- 3 files changed, 26 insertions(+), 33 deletions(-) diff --git a/src/Avalonia.Base/AvaloniaProperty.cs b/src/Avalonia.Base/AvaloniaProperty.cs index 4b0116a536..953132116c 100644 --- a/src/Avalonia.Base/AvaloniaProperty.cs +++ b/src/Avalonia.Base/AvaloniaProperty.cs @@ -21,7 +21,7 @@ namespace Avalonia /// public static readonly object UnsetValue = new Unset(); - private static int s_nextId = 1; + private static int s_nextId; private readonly Subject _initialized; private readonly Subject _changed; private readonly PropertyMetadata _defaultMetadata; diff --git a/src/Avalonia.Base/AvaloniaPropertyRegistry.cs b/src/Avalonia.Base/AvaloniaPropertyRegistry.cs index dc75727941..11b1096052 100644 --- a/src/Avalonia.Base/AvaloniaPropertyRegistry.cs +++ b/src/Avalonia.Base/AvaloniaPropertyRegistry.cs @@ -13,8 +13,8 @@ namespace Avalonia /// public class AvaloniaPropertyRegistry { - private readonly Dictionary _allProperties = - new Dictionary(); + private readonly IList _properties = + new List(); private readonly Dictionary> _registered = new Dictionary>(); private readonly Dictionary> _attached = @@ -157,7 +157,7 @@ namespace Avalonia /// The registered property or null if no matching property found. internal AvaloniaProperty FindRegistered(int id) { - return _allProperties.TryGetValue(id, out var value) ? value : null; + return id < _properties.Count ? _properties[id] : null; } /// @@ -215,7 +215,7 @@ namespace Avalonia inner.Add(property.Id, property); } - _allProperties[property.Id] = property; + _properties.Add(property); _registeredCache.Clear(); } @@ -251,7 +251,7 @@ namespace Avalonia inner.Add(property.Id, property); } - _allProperties[property.Id] = property; + _properties.Add(property); _attachedCache.Clear(); } } diff --git a/src/Avalonia.Base/ValueStore.cs b/src/Avalonia.Base/ValueStore.cs index 7dad72b551..d520e2b80a 100644 --- a/src/Avalonia.Base/ValueStore.cs +++ b/src/Avalonia.Base/ValueStore.cs @@ -238,7 +238,7 @@ namespace Avalonia private (int, bool) TryFindEntry(int propertyId) { - if (_entries.Length <= 16) + if (_entries.Length <= 12) { // For small lists, we use an optimized linear search. Since the last item in the list // is always int.MaxValue, we can skip a conditional branch in each iteration. @@ -255,10 +255,6 @@ namespace Avalonia if (_entries[8].PropertyId >= propertyId) return (8, _entries[8].PropertyId == propertyId); if (_entries[9].PropertyId >= propertyId) return (9, _entries[9].PropertyId == propertyId); if (_entries[10].PropertyId >= propertyId) return (10, _entries[10].PropertyId == propertyId); - if (_entries[11].PropertyId >= propertyId) return (11, _entries[11].PropertyId == propertyId); - if (_entries[12].PropertyId >= propertyId) return (12, _entries[12].PropertyId == propertyId); - if (_entries[13].PropertyId >= propertyId) return (13, _entries[13].PropertyId == propertyId); - if (_entries[14].PropertyId >= propertyId) return (14, _entries[14].PropertyId == propertyId); } else { @@ -266,36 +262,33 @@ namespace Avalonia int high = _entries.Length; int id; - if (high > 0) + while (high - low > 3) { - while (high - low > 3) - { - int pivot = (high + low) / 2; - id = _entries[pivot].PropertyId; + int pivot = (high + low) / 2; + id = _entries[pivot].PropertyId; - if (propertyId == id) - return (pivot, true); + if (propertyId == id) + return (pivot, true); - if (propertyId <= id) - high = pivot; - else - low = pivot + 1; - } + if (propertyId <= id) + high = pivot; + else + low = pivot + 1; + } - do - { - id = _entries[low].PropertyId; + do + { + id = _entries[low].PropertyId; - if (id == propertyId) - return (low, true); + if (id == propertyId) + return (low, true); - if (id > propertyId) - break; + if (id > propertyId) + break; - ++low; - } - while (low < high); + ++low; } + while (low < high); } return (0, false);