fix: switch to a shared GraphemeCache and increase it's size to 512kb
This commit is contained in:
parent
4aecc983c0
commit
b6b1f02565
4 changed files with 32 additions and 13 deletions
23
src/renderer/vaxis/GraphemeCache.zig
Normal file
23
src/renderer/vaxis/GraphemeCache.zig
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
storage: *Storage,
|
||||||
|
|
||||||
|
pub const GraphemeCache = @This();
|
||||||
|
|
||||||
|
pub inline fn put(self: *@This(), bytes: []const u8) []u8 {
|
||||||
|
return self.storage.put(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub const Storage = struct {
|
||||||
|
buf: [1024 * 512]u8 = undefined,
|
||||||
|
idx: usize = 0,
|
||||||
|
|
||||||
|
pub fn put(self: *@This(), bytes: []const u8) []u8 {
|
||||||
|
if (self.idx + bytes.len > self.buf.len) self.idx = 0;
|
||||||
|
defer self.idx += bytes.len;
|
||||||
|
@memcpy(self.buf[self.idx .. self.idx + bytes.len], bytes);
|
||||||
|
return self.buf[self.idx .. self.idx + bytes.len];
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn cache(self: *@This()) GraphemeCache {
|
||||||
|
return .{ .storage = self };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
@ -2,6 +2,7 @@ const std = @import("std");
|
||||||
const vaxis = @import("vaxis");
|
const vaxis = @import("vaxis");
|
||||||
|
|
||||||
pub const Plane = @import("Plane.zig");
|
pub const Plane = @import("Plane.zig");
|
||||||
|
const GraphemeCache = @import("GraphemeCache.zig");
|
||||||
|
|
||||||
const Layer = @This();
|
const Layer = @This();
|
||||||
|
|
||||||
|
|
@ -9,6 +10,7 @@ view: View,
|
||||||
y_off: i32 = 0,
|
y_off: i32 = 0,
|
||||||
x_off: i32 = 0,
|
x_off: i32 = 0,
|
||||||
plane_: Plane,
|
plane_: Plane,
|
||||||
|
cache_storage: GraphemeCache.Storage = .{},
|
||||||
|
|
||||||
const View = struct {
|
const View = struct {
|
||||||
allocator: std.mem.Allocator,
|
allocator: std.mem.Allocator,
|
||||||
|
|
@ -57,6 +59,7 @@ pub fn init(allocator: std.mem.Allocator, opts: Options) std.mem.Allocator.Error
|
||||||
const name = "layer";
|
const name = "layer";
|
||||||
self.plane_ = .{
|
self.plane_ = .{
|
||||||
.window = self.window(),
|
.window = self.window(),
|
||||||
|
.cache = self.cache_storage.cache(),
|
||||||
.name_buf = undefined,
|
.name_buf = undefined,
|
||||||
.name_len = name.len,
|
.name_len = name.len,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ const vaxis = @import("vaxis");
|
||||||
const Buffer = @import("Buffer");
|
const Buffer = @import("Buffer");
|
||||||
const color = @import("color");
|
const color = @import("color");
|
||||||
const RGB = @import("color").RGB;
|
const RGB = @import("color").RGB;
|
||||||
|
const GraphemeCache = @import("GraphemeCache.zig");
|
||||||
|
|
||||||
const Plane = @This();
|
const Plane = @This();
|
||||||
|
|
||||||
|
|
@ -18,7 +19,7 @@ row: i32 = 0,
|
||||||
col: i32 = 0,
|
col: i32 = 0,
|
||||||
name_buf: [name_buf_len]u8,
|
name_buf: [name_buf_len]u8,
|
||||||
name_len: usize,
|
name_len: usize,
|
||||||
cache: GraphemeCache = .{},
|
cache: GraphemeCache,
|
||||||
style: vaxis.Cell.Style = .{},
|
style: vaxis.Cell.Style = .{},
|
||||||
style_base: vaxis.Cell.Style = .{},
|
style_base: vaxis.Cell.Style = .{},
|
||||||
scrolling: bool = false,
|
scrolling: bool = false,
|
||||||
|
|
@ -49,6 +50,7 @@ pub fn init(nopts: *const Options, parent_: Plane) !Plane {
|
||||||
const len = @min(nopts.name.len, name_buf_len);
|
const len = @min(nopts.name.len, name_buf_len);
|
||||||
var plane: Plane = .{
|
var plane: Plane = .{
|
||||||
.window = parent_.window.child(opts),
|
.window = parent_.window.child(opts),
|
||||||
|
.cache = parent_.cache,
|
||||||
.name_buf = undefined,
|
.name_buf = undefined,
|
||||||
.name_len = len,
|
.name_len = len,
|
||||||
.scrolling = nopts.flags == .VSCROLL,
|
.scrolling = nopts.flags == .VSCROLL,
|
||||||
|
|
@ -500,18 +502,6 @@ pub fn metrics(self: *const Plane, tab_width: usize) Buffer.Metrics {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const GraphemeCache = struct {
|
|
||||||
buf: [1024 * 32]u8 = undefined,
|
|
||||||
idx: usize = 0,
|
|
||||||
|
|
||||||
pub fn put(self: *GraphemeCache, bytes: []const u8) []u8 {
|
|
||||||
if (self.idx + bytes.len > self.buf.len) self.idx = 0;
|
|
||||||
defer self.idx += bytes.len;
|
|
||||||
@memcpy(self.buf[self.idx .. self.idx + bytes.len], bytes);
|
|
||||||
return self.buf[self.idx .. self.idx + bytes.len];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
fn to_cell_color(col: ThemeColor) vaxis.Cell.Color {
|
fn to_cell_color(col: ThemeColor) vaxis.Cell.Color {
|
||||||
return .{ .rgb = RGB.to_u8s(RGB.from_u24(col.color)) };
|
return .{ .rgb = RGB.to_u8s(RGB.from_u24(col.color)) };
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ pub const CursorShape = vaxis.Cell.CursorShape;
|
||||||
|
|
||||||
pub const style = @import("style.zig").StyleBits;
|
pub const style = @import("style.zig").StyleBits;
|
||||||
pub const styles = @import("style.zig");
|
pub const styles = @import("style.zig");
|
||||||
|
const GraphemeCache = @import("GraphemeCache.zig");
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
pub const log_name = "vaxis";
|
pub const log_name = "vaxis";
|
||||||
|
|
@ -25,6 +26,7 @@ allocator: std.mem.Allocator,
|
||||||
tty: vaxis.Tty,
|
tty: vaxis.Tty,
|
||||||
vx: vaxis.Vaxis,
|
vx: vaxis.Vaxis,
|
||||||
tty_buffer: []u8,
|
tty_buffer: []u8,
|
||||||
|
cache_storage: GraphemeCache.Storage = .{},
|
||||||
|
|
||||||
no_alternate: bool,
|
no_alternate: bool,
|
||||||
event_buffer: std.Io.Writer.Allocating,
|
event_buffer: std.Io.Writer.Allocating,
|
||||||
|
|
@ -240,6 +242,7 @@ pub fn stdplane(self: *Self) Plane {
|
||||||
const name = "root";
|
const name = "root";
|
||||||
var plane: Plane = .{
|
var plane: Plane = .{
|
||||||
.window = self.vx.window(),
|
.window = self.vx.window(),
|
||||||
|
.cache = self.cache_storage.cache(),
|
||||||
.name_buf = undefined,
|
.name_buf = undefined,
|
||||||
.name_len = name.len,
|
.name_len = name.len,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue