mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-03-03 14:32:22 +02:00
Add a comment about why we have an extra loop in replace_bytes
This commit is contained in:
parent
9b42af96f0
commit
006d224b2c
@ -538,6 +538,11 @@ fn replace_bytes(
|
||||
while let Some(i) = bytes.find_byte(src) {
|
||||
bytes[i] = replacement;
|
||||
bytes = &mut bytes[i + 1..];
|
||||
|
||||
// To search for adjacent `src` bytes we use a different strategy.
|
||||
// Since binary data tends to have long runs of NUL terminators,
|
||||
// it is faster to compare one-byte-at-a-time than to stop and start
|
||||
// memchr (through `find_byte`) for every byte in a sequence.
|
||||
while bytes.get(0) == Some(&src) {
|
||||
bytes[0] = replacement;
|
||||
bytes = &mut bytes[1..];
|
||||
|
Loading…
x
Reference in New Issue
Block a user