Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/Ramstack.HtmxToolkit/Collections/SmallDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,13 @@ private ref KeyValuePair<TKey, TValue> Find(TKey key)

while (lo <= hi)
{
var mi = (lo + hi) >> 1;
//
// Both lo and hi are non-negative and within [0..int.MaxValue],
// so their sum fits in uint. With unchecked addition, the unsigned
// right shift handles any int wraparound, making this equivalent to
// (int)(((uint)lo + (uint)hi) >> 1), but cleaner and easier to read.
//
var mi = (lo + hi) >>> 1;
if ((uint)mi >= (uint)array.Length)
break;

Expand Down Expand Up @@ -424,7 +430,13 @@ private int IndexOf(TKey key)

while (lo <= hi)
{
var mi = lo + (hi - lo >>> 1);
//
// Both lo and hi are non-negative and within [0..int.MaxValue],
// so their sum fits in uint. With unchecked addition, the unsigned
// right shift handles any int wraparound, making this equivalent to
// (int)(((uint)lo + (uint)hi) >> 1), but cleaner and easier to read.
//
var mi = (lo + hi) >>> 1;
if ((uint)mi >= (uint)array.Length)
break;

Expand Down
Loading