diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-13 09:28:38 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-13 09:28:38 -0300 |
| commit | 5c0230ea5a77f85de77ad4354788cd6c27aa1ef6 (patch) | |
| tree | e01a903bdee092965b86e118dfaab85c3bd60004 /gui/src/Sources.zig | |
| parent | 5a40dca5adb6e9e650f55f3ec6f254a13bf50493 (diff) | |
| download | computeranim-5c0230ea5a77f85de77ad4354788cd6c27aa1ef6.tar.gz computeranim-5c0230ea5a77f85de77ad4354788cd6c27aa1ef6.zip | |
debugger: follow natural V8 deoptimization with adaptive live views
Diffstat (limited to 'gui/src/Sources.zig')
| -rw-r--r-- | gui/src/Sources.zig | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/gui/src/Sources.zig b/gui/src/Sources.zig index 33268c5..3bd4cbf 100644 --- a/gui/src/Sources.zig +++ b/gui/src/Sources.zig @@ -5,15 +5,28 @@ const zt = @import("ztrace"); const Sources = @This(); const File = struct { id: u64, path: []const u8, bytes: []const u8, text: ?canim.source.Text }; files: std.ArrayList(File) = .empty, +paths: ?zt.Symbols = null, pub fn close(s: *Sources, gpa: std.mem.Allocator) void { + s.clear(gpa); + if (s.paths) |*paths| paths.deinit(); + s.* = .{}; +} + +pub fn map(s: *Sources, gpa: std.mem.Allocator, io: std.Io, from: []const u8, to: []const u8) !void { + if (s.paths == null) s.paths = .{ .gpa = gpa, .io = io }; + try s.paths.?.mapSource(from, to); + s.clear(gpa); +} + +fn clear(s: *Sources, gpa: std.mem.Allocator) void { for (s.files.items) |file| { if (file.text) |t| t.deinit(); gpa.free(file.path); gpa.free(file.bytes); } s.files.deinit(gpa); - s.* = .{}; + s.files = .empty; } pub fn get(s: *Sources, gpa: std.mem.Allocator, io: std.Io, m: zt.store.Moment, id: u64) ?*const File { @@ -21,7 +34,7 @@ pub fn get(s: *Sources, gpa: std.mem.Allocator, io: std.Io, m: zt.store.Moment, if (s.files.items.len == 32) return null; var buffer: [4096]u8 = undefined; const name = (m.string(id, &buffer) catch null) orelse return null; - const path = gpa.dupe(u8, name) catch return null; + const path = (if (s.paths) |*paths| paths.sourcePath(.{ .key = 0, .dir = "", .name = name, .line = 0, .column = 0 }) else gpa.dupe(u8, name)) catch return null; const bytes = std.Io.Dir.cwd().readFileAlloc(io, path, gpa, .limited(8 * 1024 * 1024)) catch &.{}; const text = if (bytes.len > 0) canim.source.prepare(bytes, path) catch null else null; s.files.append(gpa, .{ .id = id, .path = path, .bytes = bytes, .text = text }) catch { |
