Skip to content

Commit a9d92a0

Browse files
committed
chore: Improve chunking when reading files for grep
1 parent 7de55be commit a9d92a0

3 files changed

Lines changed: 381 additions & 0 deletions

File tree

crates/fff-core/src/types.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,13 @@ impl FileItem {
223223
self.content = OnceLock::new();
224224
}
225225

226+
/// Returns already-cached content from the OnceLock, or `None` if not
227+
/// yet loaded. No budget check, no I/O — just an atomic load.
228+
#[inline]
229+
pub fn get_cached_content(&self) -> Option<&[u8]> {
230+
self.content.get().map(|c| &**c)
231+
}
232+
226233
/// Get the cached file contents or lazily load and cache them.
227234
///
228235
/// Returns `None` if the file is too large, empty, can't be opened, **or
@@ -288,6 +295,7 @@ impl FileItem {
288295
file.read_exact(buf).ok()?;
289296
Some(buf.as_slice())
290297
}
298+
291299
}
292300

293301
/// Page size on Apple Silicon is 16KB; on x86-64 it's 4KB.

crates/fff-nvim/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ tempfile = "3.8"
9393
name = "indexing_and_search"
9494
harness = false
9595

96+
[[bench]]
97+
name = "grep_bench"
98+
harness = false
99+
96100
[[bench]]
97101
name = "query_tracker_bench"
98102
harness = false

0 commit comments

Comments
 (0)