Skip to content

Commit

Permalink
fix merge
Browse files Browse the repository at this point in the history
  • Loading branch information
dylan-conway committed Feb 1, 2024
1 parent db1f65a commit 5cb4af1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 41 deletions.
71 changes: 31 additions & 40 deletions src/string_immutable.zig
Original file line number Diff line number Diff line change
Expand Up @@ -43,54 +43,48 @@ pub fn toUTF16Literal(comptime str: []const u8) []const u16 {
return comptime literal(u16, str);
}

pub fn literal(comptime T: type, comptime str: string) []const T {
pub inline fn literal(comptime T: type, comptime str: string) []const T {
if (!@inComptime()) @compileError("strings.literal() should be called in a comptime context");
return comptime brk: {
comptime var output: [str.len]T = undefined;
comptime var output: [str.len]T = undefined;

for (str, 0..) |c, i| {
// TODO(dylan-conway): should we check for non-ascii characters like JSC does with operator""_s
output[i] = c;
}
for (str, 0..) |c, i| {
// TODO(dylan-conway): should we check for non-ascii characters like JSC does with operator""_s
output[i] = c;
}

const Static = struct {
pub const literal: []const T = output[0..];
};
break :brk Static.literal;
const Static = struct {
pub const literal: []const T = output[0..];
};
return Static.literal;
}

pub fn literalBuf(comptime T: type, comptime str: string) [str.len]T {
pub inline fn literalBuf(comptime T: type, comptime str: string) [str.len]T {
if (!@inComptime()) @compileError("strings.literalBuf() should be called in a comptime context");
return comptime brk: {
comptime var output: [str.len]T = undefined;
comptime var output: [str.len]T = undefined;

for (str, 0..) |c, i| {
// TODO(dylan-conway): should we check for non-ascii characters like JSC does with operator""_s
output[i] = c;
}
for (str, 0..) |c, i| {
// TODO(dylan-conway): should we check for non-ascii characters like JSC does with operator""_s
output[i] = c;
}

const Static = struct {
pub const literal: [str.len]T = output;
};
break :brk Static.literal;
const Static = struct {
pub const literal: [str.len]T = output;
};
return Static.literal;
}

pub fn toUTF16LiteralZ(comptime str: []const u8) [:0]const u16 {
return comptime brk: {
comptime var output: [str.len + 1]u16 = undefined;
pub inline fn toUTF16LiteralZ(comptime str: []const u8) [:0]const u16 {
comptime var output: [str.len + 1]u16 = undefined;

for (str, 0..) |c, i| {
output[i] = c;
}
output[str.len] = 0;
for (str, 0..) |c, i| {
output[i] = c;
}
output[str.len] = 0;

const Static = struct {
pub const literal: [:0]const u16 = output[0..str.len :0];
};
break :brk Static.literal;
const Static = struct {
pub const literal: [:0]const u16 = output[0..str.len :0];
};
return Static.literal;
}

pub const OptionalUsize = std.meta.Int(.unsigned, @bitSizeOf(usize) - 1);
Expand Down Expand Up @@ -887,13 +881,10 @@ pub fn hasPrefixComptimeType(comptime T: type, self: []const T, comptime alt: an
const rhs = comptime switch (T) {
u8 => alt,
u16 => switch (std.meta.Child(@TypeOf(alt))) {
u8 => w(alt),
else => |t| switch (std.meta.Child(t)) {
u8 => w(alt),
else => alt,
},
u16 => alt,
else => w(alt),
},
else => unreachable,
else => @compileError("Unsupported type given to hasPrefixComptimeType"),
};
return self.len >= alt.len and eqlComptimeCheckLenWithType(T, self[0..rhs.len], rhs, false);
}
Expand Down Expand Up @@ -1740,7 +1731,7 @@ pub fn addNTPathPrefix(wbuf: []u16, utf16: []const u16) [:0]const u16 {
}

pub fn addNTPathPrefixIfNeeded(wbuf: []u16, utf16: []const u16) [:0]const u16 {
if (hasPrefixComptimeType(u16, utf16, &bun.windows.nt_object_prefix)) {
if (hasPrefixComptimeType(u16, utf16, bun.windows.nt_object_prefix)) {
@memcpy(wbuf[0..utf16.len], utf16);
wbuf[utf16.len] = 0;
return wbuf[0..utf16.len :0];
Expand Down
2 changes: 1 addition & 1 deletion src/sys.zig
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ pub fn ntCreateFile(
// file specification, provided that the floppy driver and overlying file system are already
// loaded. For more information, see File Names, Paths, and Namespaces.
.ObjectName = &nt_name,
.RootDirectory = if (bun.strings.hasPrefixComptimeType(u16, path, &windows.nt_object_prefix))
.RootDirectory = if (bun.strings.hasPrefixComptimeType(u16, path, windows.nt_object_prefix))
null
else if (dir == bun.invalid_fd)
std.fs.cwd().fd
Expand Down

0 comments on commit 5cb4af1

Please sign in to comment.