Skip to content
Snippets Groups Projects
Commit cc1966d6 authored by Yorhel's avatar Yorhel
Browse files

Make some space for shared size in UI + speed up JSON import a bit

It still feels kind of sluggish, but not entirely sure how to improve
it.
parent e6b2cff3
No related branches found
No related tags found
No related merge requests found
...@@ -180,7 +180,7 @@ const Row = struct { ...@@ -180,7 +180,7 @@ const Row = struct {
fn size(self: *Self) void { fn size(self: *Self) void {
var width = if (main.config.si) @as(u32, 9) else 10; var width = if (main.config.si) @as(u32, 9) else 10;
if (dir_has_shared and main.config.show_shared != .off) if (dir_has_shared and main.config.show_shared != .off)
width += 1 + width; width += 2 + width;
defer self.col += width; defer self.col += width;
const item = self.item orelse return; const item = self.item orelse return;
const siz = if (main.config.show_blocks) blocksToSize(item.blocks) else item.size; const siz = if (main.config.show_blocks) blocksToSize(item.blocks) else item.size;
......
...@@ -410,7 +410,12 @@ pub fn scanRoot(path: []const u8, out: ?std.fs.File) !void { ...@@ -410,7 +410,12 @@ pub fn scanRoot(path: []const u8, out: ?std.fs.File) !void {
// tests can be written. // tests can be written.
const Import = struct { const Import = struct {
ctx: Context, ctx: Context,
rd: std.io.BufferedReader(4096, std.fs.File.Reader),
rd: std.fs.File,
rdoff: usize = 0,
rdsize: usize = 0,
rdbuf: [8*1024]u8 = undefined,
ch: u8 = 0, // last read character, 0 = EOF (or invalid null byte, who cares) ch: u8 = 0, // last read character, 0 = EOF (or invalid null byte, who cares)
byte: u64 = 1, byte: u64 = 1,
line: u64 = 1, line: u64 = 1,
...@@ -424,17 +429,21 @@ const Import = struct { ...@@ -424,17 +429,21 @@ const Import = struct {
// Advance to the next byte, sets ch. // Advance to the next byte, sets ch.
fn con(self: *Self) void { fn con(self: *Self) void {
// XXX: This indirection through a BufferedReader to just read 1 byte if (self.rdoff >= self.rdsize) {
// at a time may have some extra overhead. Wrapping our own LinearFifo self.rdoff = 0;
// may or may not be worth it, needs benchmarking. self.rdsize = self.rd.read(&self.rdbuf) catch |e| switch (e) {
self.ch = self.rd.reader().readByte() catch |e| switch (e) {
error.EndOfStream => 0,
error.InputOutput => self.die("I/O error"), error.InputOutput => self.die("I/O error"),
error.IsDir => self.die("not a file"), // should be detected at open() time, but no flag for that... error.IsDir => self.die("not a file"), // should be detected at open() time, but no flag for that...
// TODO: This one can be retried
error.SystemResources => self.die("out of memory"), error.SystemResources => self.die("out of memory"),
else => unreachable, else => unreachable,
}; };
if (self.rdsize == 0) {
self.ch = 0;
return;
}
}
self.ch = self.rdbuf[self.rdoff];
self.rdoff += 1;
self.byte += 1; self.byte += 1;
} }
...@@ -472,7 +481,6 @@ const Import = struct { ...@@ -472,7 +481,6 @@ const Import = struct {
// Any characters beyond the size of the buffer are consumed but otherwise discarded. // Any characters beyond the size of the buffer are consumed but otherwise discarded.
// (May store fewer characters in the case of \u escapes, it's not super precise) // (May store fewer characters in the case of \u escapes, it's not super precise)
fn string(self: *Self, buf: []u8) []u8 { fn string(self: *Self, buf: []u8) []u8 {
std.debug.assert(self.ch == '"');
if (self.next() != '"') self.die("expected '\"'"); if (self.next() != '"') self.die("expected '\"'");
var n: u64 = 0; var n: u64 = 0;
while (true) { while (true) {
...@@ -788,7 +796,7 @@ pub fn importRoot(path: [:0]const u8, out: ?std.fs.File) void { ...@@ -788,7 +796,7 @@ pub fn importRoot(path: [:0]const u8, out: ?std.fs.File) void {
var imp = Import{ var imp = Import{
.ctx = if (out) |f| Context.initFile(f) else Context.initMem(), .ctx = if (out) |f| Context.initFile(f) else Context.initMem(),
.rd = std.io.bufferedReader(fd.reader()), .rd = fd,
}; };
active_context = &imp.ctx; active_context = &imp.ctx;
defer active_context = null; defer active_context = null;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment