mirror of
https://github.com/uutils/grep.git
synced 2026-06-10 16:15:11 -07:00
28186e9ec3867c70cbdaa6988fbb9e24b95a2195
Literal searches were ~50-70x slower than GNU grep because every line paid per-line costs (terminator scan, NUL scan, dispatch) even when a buffer held no match. Add a buffer-at-a-time driver that scans whole chunks with a substring searcher and only locates line boundaries around the matches it finds; a chunk with no match costs a single vectorized sweep and no per-line work. The driver activates only for plain ASCII literal patterns (case sensitive, no metacharacters) in the simpler output modes: -c, -l, -L, -q, and plain line printing with -n/-b/filename/-m. Anything needing match positions, context, inversion, color, or special binary handling falls back to the unchanged line-at-a-time path. Output stays byte-identical to that path, including binary/invalid-UTF-8 behavior. - line_buffer: read_chunk() yields the largest span of complete lines. - matcher: expose per-pattern memmem searchers when every pattern is a plain literal (plain_literal()). - searcher: eligible_for_fast_path(), fast_locate(), fast_print(). All scanning rides on the memchr crate (SIMD memchr/memrchr/memmem). Unit tests for read_chunk and plain_literal; integration tests for prefixes, -m, and multi-chunk line-number correctness. Benchmarks (31 MB corpus) vs prior release: -F (no match): 232ms -> 15ms (15.9x; now faster than GNU) -c literal: 229ms -> 15ms (15.2x) plain print: 248ms -> 18ms (13.5x) Regex and -i paths are unchanged (still the line-at-a-time engine).
Grep, now in Rust
A Rust implementation of GNU Grep. This project is an initial release and may contain bugs.
Install
cargo install uu_grep
Building
Download Rust at: https://rustup.rs/
# Check out this repository
git clone https://github.com/uutils/grep
cd grep
# Build a release version
cargo build --release
# Run!
./target/release/grep --help
# Run tests (if needed; after making changes)
cargo test
Pre-commit hooks
This project uses pre-commit; run pre-commit install to enable the git hooks.
Known Issues
- Does not take
LANG, etc., into account for handling file encodings (non-UTF8 matches are treated as binary) - No localization support yet
- Performances need to be improved
Contributing
To contribute to uutils, please see CONTRIBUTING.
License
uutils is licensed under the MIT License - see the LICENSE file for details
GNU Grep is licensed under the GPL 3.0 or later.
Languages
Rust
90.9%
Shell
6.4%
Python
2.7%