From 814222a15dadda3442b8c970da70e401ad313d87 Mon Sep 17 00:00:00 2001 From: mstr2 Date: Wed, 9 Jan 2019 22:21:40 +0100 Subject: [PATCH] Reduced linear search, made FindRegistered method internal --- src/Avalonia.Base/AvaloniaPropertyRegistry.cs | 2 +- src/Avalonia.Base/ValueStore.cs | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Avalonia.Base/AvaloniaPropertyRegistry.cs b/src/Avalonia.Base/AvaloniaPropertyRegistry.cs index 7beab5f497..dc75727941 100644 --- a/src/Avalonia.Base/AvaloniaPropertyRegistry.cs +++ b/src/Avalonia.Base/AvaloniaPropertyRegistry.cs @@ -155,7 +155,7 @@ namespace Avalonia /// /// The property Id. /// The registered property or null if no matching property found. - public AvaloniaProperty FindRegistered(int id) + internal AvaloniaProperty FindRegistered(int id) { return _allProperties.TryGetValue(id, out var value) ? value : null; } diff --git a/src/Avalonia.Base/ValueStore.cs b/src/Avalonia.Base/ValueStore.cs index f78aaab221..7dad72b551 100644 --- a/src/Avalonia.Base/ValueStore.cs +++ b/src/Avalonia.Base/ValueStore.cs @@ -7,7 +7,7 @@ namespace Avalonia { internal class ValueStore : IPriorityValueOwner { - struct Entry + private struct Entry { internal int PropertyId; internal object Value; @@ -238,7 +238,7 @@ namespace Avalonia private (int, bool) TryFindEntry(int propertyId) { - if (_entries.Length <= 20) + if (_entries.Length <= 16) { // 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. @@ -259,10 +259,6 @@ namespace Avalonia 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); - if (_entries[15].PropertyId >= propertyId) return (15, _entries[15].PropertyId == propertyId); - if (_entries[16].PropertyId >= propertyId) return (16, _entries[16].PropertyId == propertyId); - if (_entries[17].PropertyId >= propertyId) return (17, _entries[17].PropertyId == propertyId); - if (_entries[18].PropertyId >= propertyId) return (18, _entries[18].PropertyId == propertyId); } else {