@@ -536,7 +536,7 @@ private unsafe ref string TryGet(ReadOnlySpan<char> span, int hashcode)
536
536
( uint ) i < ( uint ) length ;
537
537
i = entry . NextIndex )
538
538
{
539
- entry = ref Unsafe . Add ( ref mapEntriesRef , ( IntPtr ) ( void * ) ( uint ) i ) ;
539
+ entry = ref Unsafe . Add ( ref mapEntriesRef , ( nint ) ( uint ) i ) ;
540
540
541
541
if ( entry . HashCode == hashcode &&
542
542
entry . Value ! . AsSpan ( ) . SequenceEqual ( span ) )
@@ -556,7 +556,7 @@ private unsafe ref string TryGet(ReadOnlySpan<char> span, int hashcode)
556
556
/// <param name="value">The new <see cref="string"/> instance to store.</param>
557
557
/// <param name="hashcode">The precomputed hashcode for <paramref name="value"/>.</param>
558
558
[ MethodImpl ( MethodImplOptions . NoInlining ) ]
559
- private unsafe void Insert ( string value , int hashcode )
559
+ private void Insert ( string value , int hashcode )
560
560
{
561
561
ref int bucketsRef = ref this . buckets . DangerousGetReference ( ) ;
562
562
ref MapEntry mapEntriesRef = ref this . mapEntries . DangerousGetReference ( ) ;
@@ -571,7 +571,7 @@ private unsafe void Insert(string value, int hashcode)
571
571
entryIndex = heapEntriesRef . MapIndex ;
572
572
heapIndex = 0 ;
573
573
574
- ref MapEntry removedEntry = ref Unsafe . Add ( ref mapEntriesRef , ( IntPtr ) ( void * ) ( uint ) entryIndex ) ;
574
+ ref MapEntry removedEntry = ref Unsafe . Add ( ref mapEntriesRef , ( nint ) ( uint ) entryIndex ) ;
575
575
576
576
// The removal logic can be extremely optimized in this case, as we
577
577
// can retrieve the precomputed hashcode for the target entry by doing
@@ -588,9 +588,9 @@ private unsafe void Insert(string value, int hashcode)
588
588
}
589
589
590
590
int bucketIndex = hashcode & ( this . buckets . Length - 1 ) ;
591
- ref int targetBucket = ref Unsafe . Add ( ref bucketsRef , ( IntPtr ) ( void * ) ( uint ) bucketIndex ) ;
592
- ref MapEntry targetMapEntry = ref Unsafe . Add ( ref mapEntriesRef , ( IntPtr ) ( void * ) ( uint ) entryIndex ) ;
593
- ref HeapEntry targetHeapEntry = ref Unsafe . Add ( ref heapEntriesRef , ( IntPtr ) ( void * ) ( uint ) heapIndex ) ;
591
+ ref int targetBucket = ref Unsafe . Add ( ref bucketsRef , ( nint ) ( uint ) bucketIndex ) ;
592
+ ref MapEntry targetMapEntry = ref Unsafe . Add ( ref mapEntriesRef , ( nint ) ( uint ) entryIndex ) ;
593
+ ref HeapEntry targetHeapEntry = ref Unsafe . Add ( ref heapEntriesRef , ( nint ) ( uint ) heapIndex ) ;
594
594
595
595
// Assign the values in the new map entry
596
596
targetMapEntry . HashCode = hashcode ;
@@ -616,7 +616,7 @@ private unsafe void Insert(string value, int hashcode)
616
616
/// <param name="mapIndex">The index of the target map node to remove.</param>
617
617
/// <remarks>The input <see cref="string"/> instance needs to already exist in the map.</remarks>
618
618
[ MethodImpl ( MethodImplOptions . NoInlining ) ]
619
- private unsafe void Remove ( int hashcode , int mapIndex )
619
+ private void Remove ( int hashcode , int mapIndex )
620
620
{
621
621
ref MapEntry mapEntriesRef = ref this . mapEntries . DangerousGetReference ( ) ;
622
622
int
@@ -628,15 +628,15 @@ private unsafe void Remove(int hashcode, int mapIndex)
628
628
// value we're looking for is guaranteed to be present
629
629
while ( true )
630
630
{
631
- ref MapEntry candidate = ref Unsafe . Add ( ref mapEntriesRef , ( IntPtr ) ( void * ) ( uint ) entryIndex ) ;
631
+ ref MapEntry candidate = ref Unsafe . Add ( ref mapEntriesRef , ( nint ) ( uint ) entryIndex ) ;
632
632
633
633
// Check the current value for a match
634
634
if ( entryIndex == mapIndex )
635
635
{
636
636
// If this was not the first list node, update the parent as well
637
637
if ( lastIndex != EndOfList )
638
638
{
639
- ref MapEntry lastEntry = ref Unsafe . Add ( ref mapEntriesRef , ( IntPtr ) ( void * ) ( uint ) lastIndex ) ;
639
+ ref MapEntry lastEntry = ref Unsafe . Add ( ref mapEntriesRef , ( nint ) ( uint ) lastIndex ) ;
640
640
641
641
lastEntry . NextIndex = candidate . NextIndex ;
642
642
}
@@ -662,14 +662,14 @@ private unsafe void Remove(int hashcode, int mapIndex)
662
662
/// </summary>
663
663
/// <param name="heapIndex">The index of the target heap node to update.</param>
664
664
[ MethodImpl ( MethodImplOptions . NoInlining ) ]
665
- private unsafe void UpdateTimestamp ( ref int heapIndex )
665
+ private void UpdateTimestamp ( ref int heapIndex )
666
666
{
667
667
int
668
668
currentIndex = heapIndex ,
669
669
count = this . count ;
670
670
ref MapEntry mapEntriesRef = ref this . mapEntries . DangerousGetReference ( ) ;
671
671
ref HeapEntry heapEntriesRef = ref this . heapEntries . DangerousGetReference ( ) ;
672
- ref HeapEntry root = ref Unsafe . Add ( ref heapEntriesRef , ( IntPtr ) ( void * ) ( uint ) currentIndex ) ;
672
+ ref HeapEntry root = ref Unsafe . Add ( ref heapEntriesRef , ( nint ) ( uint ) currentIndex ) ;
673
673
uint timestamp = this . timestamp ;
674
674
675
675
// Check if incrementing the current timestamp for the heap node to update
@@ -721,7 +721,7 @@ private unsafe void UpdateTimestamp(ref int heapIndex)
721
721
// Check and update the left child, if necessary
722
722
if ( left < count )
723
723
{
724
- ref HeapEntry child = ref Unsafe . Add ( ref heapEntriesRef , ( IntPtr ) ( void * ) ( uint ) left ) ;
724
+ ref HeapEntry child = ref Unsafe . Add ( ref heapEntriesRef , ( nint ) ( uint ) left ) ;
725
725
726
726
if ( child . Timestamp < minimum . Timestamp )
727
727
{
@@ -733,7 +733,7 @@ private unsafe void UpdateTimestamp(ref int heapIndex)
733
733
// Same check as above for the right child
734
734
if ( right < count )
735
735
{
736
- ref HeapEntry child = ref Unsafe . Add ( ref heapEntriesRef , ( IntPtr ) ( void * ) ( uint ) right ) ;
736
+ ref HeapEntry child = ref Unsafe . Add ( ref heapEntriesRef , ( nint ) ( uint ) right ) ;
737
737
738
738
if ( child . Timestamp < minimum . Timestamp )
739
739
{
@@ -752,8 +752,8 @@ private unsafe void UpdateTimestamp(ref int heapIndex)
752
752
}
753
753
754
754
// Update the indices in the respective map entries (accounting for the swap)
755
- Unsafe . Add ( ref mapEntriesRef , ( IntPtr ) ( void * ) ( uint ) root . MapIndex ) . HeapIndex = targetIndex ;
756
- Unsafe . Add ( ref mapEntriesRef , ( IntPtr ) ( void * ) ( uint ) minimum . MapIndex ) . HeapIndex = currentIndex ;
755
+ Unsafe . Add ( ref mapEntriesRef , ( nint ) ( uint ) root . MapIndex ) . HeapIndex = targetIndex ;
756
+ Unsafe . Add ( ref mapEntriesRef , ( nint ) ( uint ) minimum . MapIndex ) . HeapIndex = currentIndex ;
757
757
758
758
currentIndex = targetIndex ;
759
759
@@ -764,7 +764,7 @@ private unsafe void UpdateTimestamp(ref int heapIndex)
764
764
minimum = temp ;
765
765
766
766
// Update the reference to the root node
767
- root = ref Unsafe . Add ( ref heapEntriesRef , ( IntPtr ) ( void * ) ( uint ) currentIndex ) ;
767
+ root = ref Unsafe . Add ( ref heapEntriesRef , ( nint ) ( uint ) currentIndex ) ;
768
768
}
769
769
770
770
Fallback :
@@ -787,14 +787,14 @@ private unsafe void UpdateTimestamp(ref int heapIndex)
787
787
/// a given number of nodes, those are all contiguous from the start of the array.
788
788
/// </summary>
789
789
[ MethodImpl ( MethodImplOptions . NoInlining ) ]
790
- private unsafe void UpdateAllTimestamps ( )
790
+ private void UpdateAllTimestamps ( )
791
791
{
792
792
int count = this . count ;
793
793
ref HeapEntry heapEntriesRef = ref this . heapEntries . DangerousGetReference ( ) ;
794
794
795
795
for ( int i = 0 ; i < count ; i ++ )
796
796
{
797
- Unsafe . Add ( ref heapEntriesRef , ( IntPtr ) ( void * ) ( uint ) i ) . Timestamp = ( uint ) i ;
797
+ Unsafe . Add ( ref heapEntriesRef , ( nint ) ( uint ) i ) . Timestamp = ( uint ) i ;
798
798
}
799
799
}
800
800
}
0 commit comments