memory optimisation

This commit is contained in:
2025-12-02 19:32:31 +01:00
parent 52d1df4c2f
commit 75df916d97
3 changed files with 12 additions and 8 deletions

View File

@@ -141,13 +141,10 @@ fn search_lines(
// Read lines in this chunk efficiently (one seek, sequential reads)
let lines = line_index.read_line_range(&mut file_handle, *start, *end);
// Process each line
// Process each line - only store line numbers, not content
for (line_number, content) in lines {
if params.matches_line(&content, &regex_matcher) {
chunk_results.push(FilteredLine {
line_number,
content,
});
chunk_results.push(FilteredLine { line_number });
}
}

View File

@@ -7,8 +7,9 @@ pub struct HighlightRule {
pub enabled: bool,
}
// Filtered lines now only store line numbers to save memory
// Content is loaded on-demand when rendering
#[derive(Clone)]
pub struct FilteredLine {
pub line_number: usize,
pub content: String,
}

View File

@@ -161,15 +161,21 @@ fn render_visible_lines(
fn get_line_content(tab: &mut FileTab, show_all: bool, display_idx: usize) -> (usize, String) {
if show_all {
// Main view: read line by display index
let content = tab
.line_index
.read_line(&mut tab.file_handle, display_idx)
.unwrap_or_default();
(display_idx, content)
} else {
// Filtered view: get line number from filtered list, then read content on-demand
if display_idx < tab.filtered_lines.len() {
let filtered = &tab.filtered_lines[display_idx];
(filtered.line_number, filtered.content.clone())
let line_number = tab.filtered_lines[display_idx].line_number;
let content = tab
.line_index
.read_line(&mut tab.file_handle, line_number)
.unwrap_or_default();
(line_number, content)
} else {
(0, String::new())
}