Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Commit

Permalink
By ref in indexer
Browse files Browse the repository at this point in the history
  • Loading branch information
danmoseley authored and Anthony Lloyd committed Nov 5, 2018
1 parent ce4005c commit d26e0fd
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,12 @@ public ref TValue this[TKey key]

while (entryIndex != -1)
{
if (entries[entryIndex].key.Equals(key))
ref Entry candidate = ref entries[entryIndex];
if (candidate.key.Equals(key))
{
return ref entries[entryIndex].value;
return ref candidate.value;
}
entryIndex = entries[entryIndex].next;
entryIndex = candidate.next;
}

if (_freeList != -1)
Expand All @@ -159,11 +160,14 @@ public ref TValue this[TKey key]
entryIndex = Count;
}

entries[entryIndex].key = key;
entries[entryIndex].next = _buckets[bucketIndex] - 1;
_buckets[bucketIndex] = entryIndex + 1;
ref Entry entry = ref entries[entryIndex];
entry.key = key;

ref int bucket = ref _buckets[bucketIndex];
entry.next = bucket - 1;
bucket = entryIndex + 1;
Count++;
return ref entries[entryIndex].value;
return ref entry.value;
}
}

Expand Down

0 comments on commit d26e0fd

Please sign in to comment.