memory optimisation
This commit is contained in:
@@ -141,13 +141,10 @@ fn search_lines(
|
|||||||
// Read lines in this chunk efficiently (one seek, sequential reads)
|
// Read lines in this chunk efficiently (one seek, sequential reads)
|
||||||
let lines = line_index.read_line_range(&mut file_handle, *start, *end);
|
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 {
|
for (line_number, content) in lines {
|
||||||
if params.matches_line(&content, ®ex_matcher) {
|
if params.matches_line(&content, ®ex_matcher) {
|
||||||
chunk_results.push(FilteredLine {
|
chunk_results.push(FilteredLine { line_number });
|
||||||
line_number,
|
|
||||||
content,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,8 +7,9 @@ pub struct HighlightRule {
|
|||||||
pub enabled: bool,
|
pub enabled: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Filtered lines now only store line numbers to save memory
|
||||||
|
// Content is loaded on-demand when rendering
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct FilteredLine {
|
pub struct FilteredLine {
|
||||||
pub line_number: usize,
|
pub line_number: usize,
|
||||||
pub content: String,
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -161,15 +161,21 @@ fn render_visible_lines(
|
|||||||
|
|
||||||
fn get_line_content(tab: &mut FileTab, show_all: bool, display_idx: usize) -> (usize, String) {
|
fn get_line_content(tab: &mut FileTab, show_all: bool, display_idx: usize) -> (usize, String) {
|
||||||
if show_all {
|
if show_all {
|
||||||
|
// Main view: read line by display index
|
||||||
let content = tab
|
let content = tab
|
||||||
.line_index
|
.line_index
|
||||||
.read_line(&mut tab.file_handle, display_idx)
|
.read_line(&mut tab.file_handle, display_idx)
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
(display_idx, content)
|
(display_idx, content)
|
||||||
} else {
|
} else {
|
||||||
|
// Filtered view: get line number from filtered list, then read content on-demand
|
||||||
if display_idx < tab.filtered_lines.len() {
|
if display_idx < tab.filtered_lines.len() {
|
||||||
let filtered = &tab.filtered_lines[display_idx];
|
let line_number = tab.filtered_lines[display_idx].line_number;
|
||||||
(filtered.line_number, filtered.content.clone())
|
let content = tab
|
||||||
|
.line_index
|
||||||
|
.read_line(&mut tab.file_handle, line_number)
|
||||||
|
.unwrap_or_default();
|
||||||
|
(line_number, content)
|
||||||
} else {
|
} else {
|
||||||
(0, String::new())
|
(0, String::new())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user