refactor: add ascii optimization to Plane.egc_length
This gives a huge performance boost to pos_to_width which is used by find results and many other things.
This commit is contained in:
parent
152eed7847
commit
e37c17452f
1 changed files with 23 additions and 23 deletions
|
|
@ -437,26 +437,24 @@ inline fn set_font_style(style: *vaxis.Cell.Style, fs: FontStyle) void {
|
|||
}
|
||||
}
|
||||
|
||||
inline fn is_control_code(c: u8) bool {
|
||||
return switch (c) {
|
||||
0...8, 10...31 => true,
|
||||
else => false,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn egc_length(self: *const Plane, egcs: []const u8, colcount: *usize, abs_col: usize, tab_width: usize) usize {
|
||||
if (egcs.len == 0) {
|
||||
colcount.* = 0;
|
||||
return 0;
|
||||
}
|
||||
if (is_control_code(egcs[0])) {
|
||||
switch (egcs[0]) {
|
||||
0...8,
|
||||
10...31, //control codes
|
||||
32...126,
|
||||
=> { //ascii
|
||||
colcount.* = 1;
|
||||
return 1;
|
||||
}
|
||||
if (egcs[0] == '\t') {
|
||||
},
|
||||
'\t' => {
|
||||
colcount.* = tab_width - (abs_col % tab_width);
|
||||
return 1;
|
||||
}
|
||||
},
|
||||
else => {
|
||||
var iter = vaxis.unicode.graphemeIterator(egcs);
|
||||
const grapheme = iter.next() orelse {
|
||||
colcount.* = 1;
|
||||
|
|
@ -466,6 +464,8 @@ pub fn egc_length(self: *const Plane, egcs: []const u8, colcount: *usize, abs_co
|
|||
const w = self.window.gwidth(s);
|
||||
colcount.* = w;
|
||||
return s.len;
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn egc_chunk_width(self: *const Plane, chunk_: []const u8, abs_col_: usize, tab_width: usize) usize {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue