1
0
mirror of https://github.com/BurntSushi/ripgrep.git synced 2025-03-17 20:28:03 +02:00

ignore: simplify the work-stealing strategy

There's no particular reason for this change. I happened to be looking
at the code again and realized that stealing from your left neighbour
or your right neighbour shouldn't make a difference (and indeed perf is
the same in my benchmarks).

Closes #2624
This commit is contained in:
Tavian Barnes 2023-10-11 16:17:29 -04:00 committed by Andrew Gallant
parent 8b766a2522
commit 53679e4c43

View File

@ -1439,15 +1439,15 @@ impl Stack {
/// Steal a message from another queue.
fn steal(&self) -> Option<Message> {
// For fairness, try to steal from index - 1, then index - 2, ... 0,
// then wrap around to len - 1, len - 2, ... index + 1.
// For fairness, try to steal from index + 1, index + 2, ... len - 1,
// then wrap around to 0, 1, ... index - 1.
let (left, right) = self.stealers.split_at(self.index);
// Don't steal from ourselves
let right = &right[1..];
left.iter()
.rev()
.chain(right.iter().rev())
right
.iter()
.chain(left.iter())
.map(|s| s.steal_batch_and_pop(&self.deque))
.find_map(|s| s.success())
}