Browse Source

Reduced linear search, made FindRegistered method internal

pull/2209/head
mstr2 8 years ago
parent
commit
814222a15d
  1. 2
      src/Avalonia.Base/AvaloniaPropertyRegistry.cs
  2. 8
      src/Avalonia.Base/ValueStore.cs

2
src/Avalonia.Base/AvaloniaPropertyRegistry.cs

@ -155,7 +155,7 @@ namespace Avalonia
/// </summary> /// </summary>
/// <param name="id">The property Id.</param> /// <param name="id">The property Id.</param>
/// <returns>The registered property or null if no matching property found.</returns> /// <returns>The registered property or null if no matching property found.</returns>
public AvaloniaProperty FindRegistered(int id) internal AvaloniaProperty FindRegistered(int id)
{ {
return _allProperties.TryGetValue(id, out var value) ? value : null; return _allProperties.TryGetValue(id, out var value) ? value : null;
} }

8
src/Avalonia.Base/ValueStore.cs

@ -7,7 +7,7 @@ namespace Avalonia
{ {
internal class ValueStore : IPriorityValueOwner internal class ValueStore : IPriorityValueOwner
{ {
struct Entry private struct Entry
{ {
internal int PropertyId; internal int PropertyId;
internal object Value; internal object Value;
@ -238,7 +238,7 @@ namespace Avalonia
private (int, bool) TryFindEntry(int propertyId) 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 // 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. // 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[12].PropertyId >= propertyId) return (12, _entries[12].PropertyId == propertyId);
if (_entries[13].PropertyId >= propertyId) return (13, _entries[13].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[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 else
{ {

Loading…
Cancel
Save