editor: Improve slice_line method performance. (#1290)

Now we can handle more than 200K lines (before is 150K).
This commit is contained in:
Jason Lee 2025-09-25 18:54:06 +08:00 committed by GitHub
parent ef1d727c3d
commit 9f1423324a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -221,16 +221,20 @@ pub trait RopeExt {
impl RopeExt for Rope {
fn slice_line(&self, row: usize) -> RopeSlice<'_> {
if row >= self.lines_len() {
let total_lines = self.lines_len();
if row >= total_lines {
return self.slice(0..0);
}
let line = self.line(row, LineType::LF_CR);
if line.len() > 0 && line.chars().last() == Some('\n') {
line.slice(..line.len().saturating_sub(1))
} else {
line
if line.len() > 0 {
let line_end = line.len() - 1;
if line.is_char_boundary(line_end) && line.char(line_end) == '\n' {
return line.slice(..line_end);
}
}
line
}
fn slice_lines(&self, rows_range: Range<usize>) -> RopeSlice<'_> {