Skip to content

Commit cde211e

Browse files
committed
perf: remove unneded index clamp
1 parent 24c7e76 commit cde211e

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

src/double_buffer.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ impl<'a, T> DoubleBuffer<'a, T> {
4141
/// the write buffer. The read buffer is iterated from the beginning.
4242
///
4343
/// Call `swap` after this function to commit the write buffer state.
44+
///
45+
/// Returning an out-of-bounds index from the indexer causes this function
46+
/// to immediately return, without iterating over the remaining elements.
4447
pub fn scatter<F>(&mut self, mut indexer: F)
4548
where
4649
F: FnMut(&T) -> usize,

src/sort.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,13 @@ macro_rules! sort_impl {
149149

150150
let offset = &mut working_offsets[bucket];
151151

152-
// Make sure the offset is in bounds. An unreliable key function, which
153-
// returns different keys for the same element when called repeatedly,
154-
// can cause offsets to go out of bounds.
155-
let clamped_offset = usize::min(*offset as usize, len - 1);
152+
let index = *offset as usize;
156153

157154
// Increment the offset of the bucket. Use wrapping add in case the
158155
// key function is unreliable and the bucket overflowed.
159156
*offset = offset.wrapping_add(1);
160157

161-
clamped_offset
158+
index
162159
});
163160

164161
// Check that each bucket had the same number of insertions as we expected.

0 commit comments

Comments
 (0)