refactor: replace cursel_length with Buffer.Node.get_range
get_range is likely much faster because it only walks the buffer tree once. Besides the performance difference it should give identical results.
This commit is contained in:
parent
8246f2b0ba
commit
18bc89edf8
2 changed files with 2 additions and 22 deletions
|
|
@ -1632,26 +1632,6 @@ pub const Editor = struct {
|
|||
return self.primary.col - self.view.col;
|
||||
}
|
||||
|
||||
pub fn cursel_length(root: Buffer.Root, cursel_: CurSel, metrics: Buffer.Metrics) usize {
|
||||
var length: usize = 0;
|
||||
var cursel = cursel_;
|
||||
cursel.check_selection(root, metrics);
|
||||
if (cursel.selection) |*sel| {
|
||||
sel.normalize();
|
||||
if (sel.begin.row == sel.end.row) {
|
||||
length = sel.end.col - sel.begin.col;
|
||||
} else {
|
||||
var row = sel.begin.row;
|
||||
while (row < sel.end.row) {
|
||||
length += root.line_width(row, metrics) catch 0;
|
||||
row += 1;
|
||||
}
|
||||
length = length + sel.end.col - sel.begin.col;
|
||||
}
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
fn update_event(self: *Self) !void {
|
||||
const primary = self.get_primary();
|
||||
const dirty = if (self.buffer) |buf| buf.is_dirty() else false;
|
||||
|
|
|
|||
|
|
@ -615,12 +615,12 @@ fn replace_cursel_with_character(ed: *Editor, root: Buffer.Root, cursel: *CurSel
|
|||
return error.Stop;
|
||||
const no_selection = try select_char_if_no_selection(cursel, root, ed.metrics);
|
||||
var begin: Cursor = undefined;
|
||||
var sel_length: usize = 1;
|
||||
if (cursel.selection) |*sel| {
|
||||
sel.normalize();
|
||||
begin = sel.*.begin;
|
||||
_ = root.get_range(sel.*, null, null, &sel_length, ed.metrics) catch return error.Stop;
|
||||
}
|
||||
|
||||
const sel_length = Editor.cursel_length(root, cursel.*, ed.metrics);
|
||||
const total_length = sel_length * egc.len;
|
||||
var sfa = std.heap.stackFallback(4096, ed.allocator);
|
||||
const sfa_allocator = sfa.get();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue