Skip to content

Commit 8e0f71f

Browse files
committed
Merge branch 'master' of https://github.com/burntsushi/ripgrep
2 parents 103ec88 + 1c3eebe commit 8e0f71f

File tree

4 files changed

+1654
-21
lines changed

4 files changed

+1654
-21
lines changed

crates/searcher/src/line_buffer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::io;
44
use bstr::ByteSlice;
55

66
/// The default buffer capacity that we use for the line buffer.
7-
pub(crate) const DEFAULT_BUFFER_CAPACITY: usize = 8 * (1 << 10); // 8 KB
7+
pub(crate) const DEFAULT_BUFFER_CAPACITY: usize = 64 * (1 << 10); // 64 KB
88

99
/// The behavior of a searcher in the face of long lines and big contexts.
1010
///

crates/searcher/src/searcher/glue.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ d
633633
haystack.push_str("a\n");
634634

635635
let byte_count = haystack.len();
636-
let exp = format!("0:a\n131186:a\n\nbyte count:{}\n", byte_count);
636+
let exp = format!("0:a\n1048690:a\n\nbyte count:{}\n", byte_count);
637637

638638
SearcherTester::new(&haystack, "a")
639639
.line_number(false)
@@ -721,14 +721,14 @@ d
721721
// Namely, it will *always* detect binary data in the current buffer
722722
// before searching it. Thus, the total number of bytes searched is
723723
// smaller than below.
724-
let exp = "0:a\n\nbyte count:32770\nbinary offset:32773\n";
724+
let exp = "0:a\n\nbyte count:262146\nbinary offset:262149\n";
725725
// In contrast, the slice readers (for multi line as well) will only
726726
// look for binary data in the initial chunk of bytes. After that
727727
// point, it only looks for binary data in matches. Note though that
728728
// the binary offset remains the same. (See the binary4 test for a case
729729
// where the offset is explicitly different.)
730730
let exp_slice =
731-
"0:a\n32770:a\n\nbyte count:32773\nbinary offset:32773\n";
731+
"0:a\n262146:a\n\nbyte count:262149\nbinary offset:262149\n";
732732

733733
SearcherTester::new(&haystack, "a")
734734
.binary_detection(BinaryDetection::quit(0))
@@ -755,12 +755,12 @@ d
755755
haystack.push_str("a\x00a\n");
756756
haystack.push_str("a\n");
757757

758-
let exp = "0:a\n\nbyte count:32770\nbinary offset:32773\n";
758+
let exp = "0:a\n\nbyte count:262146\nbinary offset:262149\n";
759759
// The binary offset for the Slice readers corresponds to the binary
760760
// data in `a\x00a\n` since the first line with binary data
761761
// (`b\x00b\n`) isn't part of a match, and is therefore undetected.
762762
let exp_slice =
763-
"0:a\n32770:a\n\nbyte count:32777\nbinary offset:32777\n";
763+
"0:a\n262146:a\n\nbyte count:262153\nbinary offset:262153\n";
764764

765765
SearcherTester::new(&haystack, "a")
766766
.binary_detection(BinaryDetection::quit(0))

tests/binary.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ use crate::util::{Dir, TestCommand};
55
// bug report: https://github.com/BurntSushi/ripgrep/issues/306
66

77
// Our haystack is the first 500 lines of Gutenberg's copy of "A Study in
8-
// Scarlet," with a NUL byte at line 237: `abcdef\x00`.
8+
// Scarlet," with a NUL byte at line 1898: `abcdef\x00`.
99
//
1010
// The position and size of the haystack is, unfortunately, significant. In
1111
// particular, the NUL byte is specifically inserted at some point *after* the
12-
// first 8192 bytes, which corresponds to the initial capacity of the buffer
12+
// first 65,536 bytes, which corresponds to the initial capacity of the buffer
1313
// that ripgrep uses to read files. (grep for DEFAULT_BUFFER_CAPACITY.) The
1414
// position of the NUL byte ensures that we can execute some search on the
1515
// initial buffer contents without ever detecting any binary data. Moreover,
16-
// when using a memory map for searching, only the first 8192 bytes are
16+
// when using a memory map for searching, only the first 65,536 bytes are
1717
// scanned for a NUL byte, so no binary bytes are detected at all when using
18-
// a memory map (unless our query matches line 237).
18+
// a memory map (unless our query matches line 1898).
1919
//
2020
// One last note: in the tests below, we use --no-mmap heavily because binary
2121
// detection with memory maps is a bit different. Namely, NUL bytes are only
@@ -40,7 +40,7 @@ rgtest!(after_match1_implicit, |dir: Dir, mut cmd: TestCommand| {
4040

4141
let expected = "\
4242
hay:1:The Project Gutenberg EBook of A Study In Scarlet, by Arthur Conan Doyle
43-
hay: WARNING: stopped searching binary file after match (found \"\\0\" byte around offset 9741)
43+
hay: WARNING: stopped searching binary file after match (found \"\\0\" byte around offset 77041)
4444
";
4545
eqnice!(expected, cmd.stdout());
4646
});
@@ -53,7 +53,7 @@ rgtest!(after_match1_explicit, |dir: Dir, mut cmd: TestCommand| {
5353

5454
let expected = "\
5555
1:The Project Gutenberg EBook of A Study In Scarlet, by Arthur Conan Doyle
56-
binary file matches (found \"\\0\" byte around offset 9741)
56+
binary file matches (found \"\\0\" byte around offset 77041)
5757
";
5858
eqnice!(expected, cmd.stdout());
5959
});
@@ -64,7 +64,7 @@ rgtest!(after_match1_stdin, |_: Dir, mut cmd: TestCommand| {
6464

6565
let expected = "\
6666
1:The Project Gutenberg EBook of A Study In Scarlet, by Arthur Conan Doyle
67-
binary file matches (found \"\\0\" byte around offset 9741)
67+
binary file matches (found \"\\0\" byte around offset 77041)
6868
";
6969
eqnice!(expected, cmd.pipe(HAY));
7070
});
@@ -85,7 +85,7 @@ rgtest!(after_match1_implicit_binary, |dir: Dir, mut cmd: TestCommand| {
8585

8686
let expected = "\
8787
hay:1:The Project Gutenberg EBook of A Study In Scarlet, by Arthur Conan Doyle
88-
hay: binary file matches (found \"\\0\" byte around offset 9741)
88+
hay: binary file matches (found \"\\0\" byte around offset 77041)
8989
";
9090
eqnice!(expected, cmd.stdout());
9191
});
@@ -200,7 +200,7 @@ rgtest!(after_match2_implicit, |dir: Dir, mut cmd: TestCommand| {
200200

201201
let expected = "\
202202
hay:1:The Project Gutenberg EBook of A Study In Scarlet, by Arthur Conan Doyle
203-
hay: WARNING: stopped searching binary file after match (found \"\\0\" byte around offset 9741)
203+
hay: WARNING: stopped searching binary file after match (found \"\\0\" byte around offset 77041)
204204
";
205205
eqnice!(expected, cmd.stdout());
206206
});
@@ -220,7 +220,7 @@ rgtest!(after_match2_implicit_text, |dir: Dir, mut cmd: TestCommand| {
220220

221221
let expected = "\
222222
hay:1:The Project Gutenberg EBook of A Study In Scarlet, by Arthur Conan Doyle
223-
hay:236:\"And yet you say he is not a medical student?\"
223+
hay:1867:\"And yet you say he is not a medical student?\"
224224
";
225225
eqnice!(expected, cmd.stdout());
226226
});
@@ -240,7 +240,7 @@ rgtest!(before_match1_explicit, |dir: Dir, mut cmd: TestCommand| {
240240
cmd.args(&["--no-mmap", "-n", "Heaven", "hay"]);
241241

242242
let expected = "\
243-
binary file matches (found \"\\0\" byte around offset 9741)
243+
binary file matches (found \"\\0\" byte around offset 77041)
244244
";
245245
eqnice!(expected, cmd.stdout());
246246
});
@@ -253,7 +253,7 @@ rgtest!(before_match1_implicit_binary, |dir: Dir, mut cmd: TestCommand| {
253253
cmd.args(&["--no-mmap", "-n", "--binary", "Heaven", "-g", "hay"]);
254254

255255
let expected = "\
256-
hay: binary file matches (found \"\\0\" byte around offset 9741)
256+
hay: binary file matches (found \"\\0\" byte around offset 77041)
257257
";
258258
eqnice!(expected, cmd.stdout());
259259
});
@@ -265,7 +265,7 @@ rgtest!(before_match1_implicit_text, |dir: Dir, mut cmd: TestCommand| {
265265
cmd.args(&["--no-mmap", "-n", "--text", "Heaven", "-g", "hay"]);
266266

267267
let expected = "\
268-
hay:238:\"No. Heaven knows what the objects of his studies are. But here we
268+
hay:1871:\"No. Heaven knows what the objects of his studies are. But here we
269269
";
270270
eqnice!(expected, cmd.stdout());
271271
});
@@ -288,7 +288,7 @@ rgtest!(before_match2_explicit, |dir: Dir, mut cmd: TestCommand| {
288288
cmd.args(&["--no-mmap", "-n", "a medical student", "hay"]);
289289

290290
let expected = "\
291-
binary file matches (found \"\\0\" byte around offset 9741)
291+
binary file matches (found \"\\0\" byte around offset 77041)
292292
";
293293
eqnice!(expected, cmd.stdout());
294294
});
@@ -300,7 +300,7 @@ rgtest!(before_match2_implicit_text, |dir: Dir, mut cmd: TestCommand| {
300300
cmd.args(&["--no-mmap", "-n", "--text", "a medical student", "-g", "hay"]);
301301

302302
let expected = "\
303-
hay:236:\"And yet you say he is not a medical student?\"
303+
hay:1867:\"And yet you say he is not a medical student?\"
304304
";
305305
eqnice!(expected, cmd.stdout());
306306
});

0 commit comments

Comments
 (0)