1
0
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:
Riccardo Attilio Galli 2024-02-04 09:53:39 -08:00
parent 9b42af96f0
commit 006d224b2c

View File

@ -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..];