Put TrackedString to use

This commit is contained in:
Lyssieth 2024-12-06 08:31:55 +02:00
parent 519c09aef6
commit 580b12b111
Signed by untrusted user who does not match committer: lyssieth
GPG key ID: 200268854934CFAB
2 changed files with 15 additions and 13 deletions

View file

@ -1,6 +1,8 @@
const std = @import("std"); const std = @import("std");
const cham = @import("chameleon"); const cham = @import("chameleon");
const TrackedString = @import("../util/trackedString.zig").TrackedString;
const log = std.log; const log = std.log;
pub const Level = log.Level; pub const Level = log.Level;
@ -18,10 +20,10 @@ pub const Color = enum {
}; };
pub const ScopeModifier = struct { pub const ScopeModifier = struct {
scope: []const u8, scope: TrackedString,
color: ?Color = .default, color: ?Color = .default,
bright: bool = false, bright: bool = false,
rename: ?[]const u8 = null, rename: ?TrackedString = null,
}; };
const Allocator = std.mem.Allocator; const Allocator = std.mem.Allocator;
@ -58,12 +60,12 @@ const Globals = struct {
file.close(); file.close();
} }
for (self.additionalScopes.items) |modifier| { for (self.additionalScopes.items) |*modifier| {
if (modifier.rename) |value| { if (modifier.*.rename) |*value| {
self.allocator.free(value); value.deinit();
} }
self.allocator.free(modifier.scope); modifier.*.scope.deinit();
} }
self.additionalScopes.deinit(); self.additionalScopes.deinit();

View file

@ -18,17 +18,17 @@ pub const TrackedString = struct {
}; };
} }
pub fn deinit(self: TrackedString) void { pub fn deinit(self: *TrackedString) void {
switch (self.kind) { switch (self.*.kind) {
.Constant => { .Constant => {
self.value = undefined; self.*.data = undefined;
self.kind = .{ .Dead = {} }; self.*.kind = .{ .Dead = {} };
}, },
.Allocated => |allocator| { .Allocated => |allocator| {
allocator.free(self.value); allocator.free(self.data);
self.value = undefined; self.*.data = undefined;
self.kind = .{ .Dead = {} }; self.*.kind = .{ .Dead = {} };
}, },
.Dead => {}, .Dead => {},