From 88bd4a5729d63f9621d9b2b48ea338318972e290 Mon Sep 17 00:00:00 2001 From: freref <35976402+freref@users.noreply.github.com> Date: Thu, 27 Feb 2025 02:37:31 +0100 Subject: [PATCH 1/3] remove: double buffering --- src/Context.zig | 1 - src/PdfHandler.zig | 19 ++++--------------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/src/Context.zig b/src/Context.zig index c9a321a..d3b7d6a 100644 --- a/src/Context.zig +++ b/src/Context.zig @@ -251,7 +251,6 @@ pub const Context = struct { } pub fn drawCurrentPage(self: *Self, win: vaxis.Window) !void { - self.pdf_handler.commitReload(); if (self.current_page == null or self.reload_page) { const winsize = try vaxis.Tty.getWinsize(self.tty.fd); const pix_per_col = try std.math.divCeil(u16, win.screen.width_pix, win.screen.width); diff --git a/src/PdfHandler.zig b/src/PdfHandler.zig index fe3b2e5..4ea7db5 100644 --- a/src/PdfHandler.zig +++ b/src/PdfHandler.zig @@ -16,7 +16,6 @@ pub const ScrollDirection = enum { Up, Down, Left, Right }; allocator: std.mem.Allocator, ctx: [*c]c.fz_context, doc: [*c]c.fz_document, -temp_doc: ?[*c]c.fz_document, total_pages: u16, current_page_number: u16, path: []const u8, @@ -62,7 +61,6 @@ pub fn init( .allocator = allocator, .ctx = ctx, .doc = doc, - .temp_doc = null, .total_pages = total_pages, .current_page_number = current_page_number, .path = path, @@ -76,36 +74,27 @@ pub fn init( } pub fn deinit(self: *Self) void { - if (self.temp_doc) |doc| c.fz_drop_document(self.ctx, doc); c.fz_drop_document(self.ctx, self.doc); c.fz_drop_context(self.ctx); } pub fn reloadDocument(self: *Self) !void { - if (self.temp_doc) |doc| { + if (self.doc) |doc| { c.fz_drop_document(self.ctx, doc); - self.temp_doc = null; + self.doc = null; } - self.temp_doc = c.fz_open_document(self.ctx, self.path.ptr) orelse { + self.doc = c.fz_open_document(self.ctx, self.path.ptr) orelse { std.debug.print("Failed to reload document\n", .{}); return PdfError.FailedToOpenDocument; }; - self.total_pages = @as(u16, @intCast(c.fz_count_pages(self.ctx, self.temp_doc.?))); + self.total_pages = @as(u16, @intCast(c.fz_count_pages(self.ctx, self.doc.?))); if (self.current_page_number >= self.total_pages) { self.current_page_number = self.total_pages - 1; } } -pub fn commitReload(self: *Self) void { - if (self.temp_doc) |doc| { - c.fz_drop_document(self.ctx, self.doc); - self.doc = doc; - self.temp_doc = null; - } -} - pub fn renderPage( self: *Self, page_number: u16, From 6efa15c19dcae1bc9242497af83b40068884045a Mon Sep 17 00:00:00 2001 From: freref <35976402+freref@users.noreply.github.com> Date: Thu, 27 Feb 2025 02:45:50 +0100 Subject: [PATCH 2/3] clarification: cache --- src/Context.zig | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Context.zig b/src/Context.zig index d3b7d6a..1259c27 100644 --- a/src/Context.zig +++ b/src/Context.zig @@ -195,6 +195,7 @@ pub const Context = struct { }, .file_changed => { try self.pdf_handler.reloadDocument(); + // we could remove the current page from the cache here self.reload_page = true; }, } From e75d1a96d779a4cda79bec25e5facec772d15a52 Mon Sep 17 00:00:00 2001 From: freref <35976402+freref@users.noreply.github.com> Date: Thu, 27 Feb 2025 15:33:07 +0100 Subject: [PATCH 3/3] build: use all cores by default --- build.zig | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/build.zig b/build.zig index 84d13a9..dc04d54 100755 --- a/build.zig +++ b/build.zig @@ -21,6 +21,11 @@ pub fn build(b: *std.Build) void { defer make_args.deinit(); make_args.append("make") catch unreachable; + + // use as many cores as possible by default (like zig) I dont know how to check for j arg + const cpu_count = std.Thread.getCpuCount() catch 1; + make_args.append(b.fmt("-j{d}", .{cpu_count})) catch unreachable; + make_args.append("-C") catch unreachable; make_args.append("deps/mupdf") catch unreachable;