mirror of
https://code.blicky.net/yorhel/ncdu.git
synced 2026-01-15 10:18:39 -09:00
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.
This commit is contained in:
parent
e6b2cff356
commit
cc1966d6a9
2 changed files with 24 additions and 16 deletions
|
|
@ -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;
|
||||||
|
|
@ -191,7 +191,7 @@ const Row = struct {
|
||||||
ui.addsize(self.bg, siz);
|
ui.addsize(self.bg, siz);
|
||||||
if (shr > 0 and main.config.show_shared != .off) {
|
if (shr > 0 and main.config.show_shared != .off) {
|
||||||
self.bg.fg(.flag);
|
self.bg.fg(.flag);
|
||||||
ui.addstr(if (main.config.show_shared == .unique) " U" else " S");
|
ui.addstr(if (main.config.show_shared == .unique) " U " else " S ");
|
||||||
ui.addsize(self.bg, shr);
|
ui.addsize(self.bg, shr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
36
src/scan.zig
36
src/scan.zig
|
|
@ -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 {
|
||||||
|
|
||||||
// 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.InputOutput => self.die("I/O error"),
|
||||||
error.EndOfStream => 0,
|
error.IsDir => self.die("not a file"), // should be detected at open() time, but no flag for that...
|
||||||
error.InputOutput => self.die("I/O error"),
|
error.SystemResources => self.die("out of memory"),
|
||||||
error.IsDir => self.die("not a file"), // should be detected at open() time, but no flag for that...
|
else => unreachable,
|
||||||
// TODO: This one can be retried
|
};
|
||||||
error.SystemResources => self.die("out of memory"),
|
if (self.rdsize == 0) {
|
||||||
else => unreachable,
|
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 {
|
||||||
// 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 {
|
||||||
|
|
||||||
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;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue