Optimize the binary search by using unsafe
The jit was not able to tell that bounds checks could be elided. Added an extra whistle for value types to allow for inlined comparisons.
This commit is contained in:
parent
e0e7ca0772
commit
7af48306fe
3 changed files with 368 additions and 330 deletions
17
PersistentMap/KeyStrategies/ComparableStrategy.cs
Normal file
17
PersistentMap/KeyStrategies/ComparableStrategy.cs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
namespace PersistentMap;
|
||||
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
// This is a comparable strategy that may squeeze some extra time out of value types
|
||||
|
||||
public readonly struct ComparableStrategy<K> : IKeyStrategy<K> where K : IComparable<K>
|
||||
{
|
||||
public bool UsesPrefixes => false;
|
||||
public bool UseBinarySearch => true;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public long GetPrefix(K key) => 0;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public int Compare(K x, K y) => x.CompareTo(y);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue