Skip to content

Commit

Permalink
remove ZigString.Slice.from .init is the exact same thing (#8632)
Browse files Browse the repository at this point in the history
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
  • Loading branch information
nektro and Jarred-Sumner authored Feb 2, 2024
1 parent 8808437 commit 4959c7d
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/bun.js/api/glob.zig
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ const ScanOpts = struct {
return null;
};

break :cwd_str_raw ZigString.Slice.from(duped, allocator);
break :cwd_str_raw ZigString.Slice.init(allocator, duped);
}

// Conver to utf-16
// Convert to utf-16
const utf16 = bun.strings.toUTF16AllocForReal(
allocator,
cwd_zig_str.slice(),
Expand All @@ -67,7 +67,7 @@ const ScanOpts = struct {
};

const ptr: [*]u8 = @ptrCast(utf16.ptr);
break :cwd_str_raw ZigString.Slice.from(ptr[0 .. utf16.len * 2], allocator);
break :cwd_str_raw ZigString.Slice.init(allocator, ptr[0 .. utf16.len * 2]);
}

// `.toSlice()` internally converts to WTF-8
Expand Down
7 changes: 0 additions & 7 deletions src/bun.js/bindings/bindings.zig
Original file line number Diff line number Diff line change
Expand Up @@ -432,13 +432,6 @@ pub const ZigString = extern struct {

pub const byteSlice = Slice.slice;

pub fn from(input: []u8, allocator: std.mem.Allocator) Slice {
return .{
.ptr = input.ptr,
.len = @as(u32, @truncate(input.len)),
.allocator = NullableAllocator.init(allocator),
};
}

pub fn fromUTF8NeverFree(input: []const u8) Slice {
return .{
Expand Down
2 changes: 1 addition & 1 deletion src/bun.js/node/types.zig
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ pub const StringOrBuffer = union(enum) {
defer global.vm().reportExtraMemory(out.len);

return .{
.encoded_slice = JSC.ZigString.Slice.from(out, bun.default_allocator),
.encoded_slice = JSC.ZigString.Slice.init(bun.default_allocator, out),
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/install/lockfile.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1646,7 +1646,7 @@ pub fn saveToDisk(this: *Lockfile, filename: stringZ) void {
.fd = bun.toFD(file.handle),
},
.dirfd = bun.invalid_fd,
.data = .{ .string = .{ .utf8 = bun.JSC.ZigString.Slice.from(bytes.items, bun.default_allocator) } },
.data = .{ .string = .{ .utf8 = bun.JSC.ZigString.Slice.init(bun.default_allocator, bytes.items) } },
},
.sync,
)) {
Expand Down

0 comments on commit 4959c7d

Please sign in to comment.