aboutsummaryrefslogtreecommitdiff
path: root/src/string_immutable.zig
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-08-21 22:53:25 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-08-21 22:53:25 -0700
commite012efa1243d09fb1de282ac0a1fa6c8b07538a5 (patch)
tree46a3d71fbfd8abccc650554bbb54dcf1415a9a1c /src/string_immutable.zig
parent468c22de0e8deff28b4b7f780c640ffe3529343a (diff)
downloadbun-e012efa1243d09fb1de282ac0a1fa6c8b07538a5.tar.gz
bun-e012efa1243d09fb1de282ac0a1fa6c8b07538a5.tar.zst
bun-e012efa1243d09fb1de282ac0a1fa6c8b07538a5.zip
Fix watcher when you move files/dirs around. It'll bust the cache and recreate it (and leak memory)
Former-commit-id: 8faf6127547411c1fdcee9e4e7440825f21ecd99
Diffstat (limited to 'src/string_immutable.zig')
-rw-r--r--src/string_immutable.zig26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/string_immutable.zig b/src/string_immutable.zig
index 7ae8bed31..84b72343e 100644
--- a/src/string_immutable.zig
+++ b/src/string_immutable.zig
@@ -38,21 +38,25 @@ pub fn cat(allocator: *std.mem.Allocator, first: string, second: string) !string
// 30 character string or a slice
pub const StringOrTinyString = struct {
- const Buffer = [30]u8;
+ pub const Max = 30;
+ const Buffer = [Max]u8;
+
remainder_buf: Buffer = undefined,
remainder_len: u7 = 0,
is_tiny_string: u1 = 0,
pub inline fn slice(this: *const StringOrTinyString) []const u8 {
- switch (this.is_tiny_string) {
- 1 => {
- return this.remainder_buf[0..this.remainder_len];
- },
- // TODO: maybe inline the readIntNative call?
- 0 => {
- const ptr = @intToPtr([*]const u8, std.mem.readIntNative(usize, this.remainder_buf[0..@sizeOf(usize)]));
- return ptr[0..std.mem.readIntNative(usize, this.remainder_buf[@sizeOf(usize) .. @sizeOf(usize) * 2])];
- },
- }
+ // This is a switch expression instead of a statement to make sure it uses the faster assembly
+ return switch (this.is_tiny_string) {
+ 1 => this.remainder_buf[0..this.remainder_len],
+ 0 => @intToPtr([*]const u8, std.mem.readIntNative(usize, this.remainder_buf[0..@sizeOf(usize)]))[0..std.mem.readIntNative(usize, this.remainder_buf[@sizeOf(usize) .. @sizeOf(usize) * 2])],
+ };
+ }
+
+ pub fn deinit(this: *StringOrTinyString, allocator: *std.mem.Allocator) void {
+ if (this.is_tiny_string == 1) return;
+
+ // var slice_ = this.slice();
+ // allocator.free(slice_);
}
pub fn init(stringy: string) StringOrTinyString {