no usingnamespace, organize jsc namespace, enable -fincremental (#19122)

Co-authored-by: Dylan Conway <35280289+dylan-conway@users.noreply.github.com>
This commit is contained in:
chloe caruso
2025-04-22 16:34:15 -07:00
committed by GitHub
parent 842fe8664e
commit 3349c995b5
271 changed files with 30131 additions and 30868 deletions

View File

@@ -11,6 +11,9 @@ const grapheme = @import("./grapheme.zig");
const JSC = bun.JSC;
const OOM = bun.OOM;
/// memmem is provided by libc on posix, but implemented in zig for windows.
pub const memmem = bun.sys.workaround_symbols.memmem;
pub const Encoding = enum {
ascii,
utf8,
@@ -25,11 +28,11 @@ pub const EncodingNonAscii = enum {
latin1,
};
pub inline fn containsChar(self: string, char: u8) bool {
pub fn containsChar(self: string, char: u8) callconv(bun.callconv_inline) bool {
return indexOfChar(self, char) != null;
}
pub inline fn containsCharT(comptime T: type, self: []const T, char: u8) bool {
pub fn containsCharT(comptime T: type, self: []const T, char: u8) callconv(bun.callconv_inline) bool {
return switch (T) {
u8 => containsChar(self, char),
u16 => std.mem.indexOfScalar(u16, self, char) != null,
@@ -37,15 +40,15 @@ pub inline fn containsCharT(comptime T: type, self: []const T, char: u8) bool {
};
}
pub inline fn contains(self: string, str: string) bool {
pub fn contains(self: string, str: string) callconv(bun.callconv_inline) bool {
return containsT(u8, self, str);
}
pub inline fn containsT(comptime T: type, self: []const T, str: []const T) bool {
pub fn containsT(comptime T: type, self: []const T, str: []const T) callconv(bun.callconv_inline) bool {
return indexOfT(T, self, str) != null;
}
pub inline fn containsCaseInsensitiveASCII(self: string, str: string) bool {
pub fn containsCaseInsensitiveASCII(self: string, str: string) callconv(bun.callconv_inline) bool {
var start: usize = 0;
while (start + str.len <= self.len) {
if (eqlCaseInsensitiveASCIIIgnoreLength(self[start..][0..str.len], str)) {
@@ -56,7 +59,7 @@ pub inline fn containsCaseInsensitiveASCII(self: string, str: string) bool {
return false;
}
pub inline fn removeLeadingDotSlash(slice: []const u8) []const u8 {
pub fn removeLeadingDotSlash(slice: []const u8) callconv(bun.callconv_inline) []const u8 {
if (slice.len >= 2) {
if ((@as(u16, @bitCast(slice[0..2].*)) == comptime std.mem.readInt(u16, "./", .little)) or
(Environment.isWindows and @as(u16, @bitCast(slice[0..2].*)) == comptime std.mem.readInt(u16, ".\\", .little)))
@@ -124,7 +127,7 @@ pub fn indexOfAnyT(comptime T: type, str: []const T, comptime chars: anytype) ?O
return null;
}
pub inline fn containsComptime(self: string, comptime str: string) bool {
pub fn containsComptime(self: string, comptime str: string) callconv(bun.callconv_inline) bool {
if (comptime str.len == 0) @compileError("Don't call this with an empty string plz.");
const start = std.mem.indexOfScalar(u8, self, str[0]) orelse return false;
@@ -148,7 +151,7 @@ pub fn inMapCaseInsensitive(self: []const u8, comptime ComptimeStringMap: anytyp
return bun.String.ascii(self).inMapCaseInsensitive(ComptimeStringMap);
}
pub inline fn containsAny(in: anytype, target: anytype) bool {
pub fn containsAny(in: anytype, target: anytype) callconv(bun.callconv_inline) bool {
for (in) |str| if (contains(if (@TypeOf(str) == u8) &[1]u8{str} else bun.span(str), target)) return true;
return false;
}
@@ -447,23 +450,23 @@ pub fn indexOfSigned(self: string, str: string) i32 {
return @as(i32, @intCast(i));
}
pub inline fn lastIndexOfChar(self: []const u8, char: u8) ?usize {
pub fn lastIndexOfChar(self: []const u8, char: u8) callconv(bun.callconv_inline) ?usize {
if (comptime Environment.isLinux) {
if (@inComptime()) {
return lastIndexOfCharT(u8, self, char);
}
const start = bun.C.memrchr(self.ptr, char, self.len) orelse return null;
const start = bun.c.memrchr(self.ptr, char, self.len) orelse return null;
const i = @intFromPtr(start) - @intFromPtr(self.ptr);
return @intCast(i);
}
return lastIndexOfCharT(u8, self, char);
}
pub inline fn lastIndexOfCharT(comptime T: type, self: []const T, char: T) ?usize {
pub fn lastIndexOfCharT(comptime T: type, self: []const T, char: T) callconv(bun.callconv_inline) ?usize {
return std.mem.lastIndexOfScalar(T, self, char);
}
pub inline fn lastIndexOf(self: string, str: string) ?usize {
pub fn lastIndexOf(self: string, str: string) callconv(bun.callconv_inline) ?usize {
return std.mem.lastIndexOf(u8, self, str);
}
@@ -488,7 +491,7 @@ pub fn indexOf(self: string, str: string) ?usize {
if (str_len == 1)
return indexOfCharUsize(self, str_ptr[0]);
const start = bun.C.memmem(self_ptr, self_len, str_ptr, str_len) orelse return null;
const start = memmem(self_ptr, self_len, str_ptr, str_len) orelse return null;
const i = @intFromPtr(start) - @intFromPtr(self_ptr);
bun.unsafeAssert(i < self_len);
@@ -609,7 +612,7 @@ pub const StringOrTinyString = struct {
bun.unsafeAssert(@sizeOf(@This()) == 32);
}
pub inline fn slice(this: *const StringOrTinyString) []const u8 {
pub fn slice(this: *const StringOrTinyString) callconv(bun.callconv_inline) []const u8 {
// This is a switch expression instead of a statement to make sure it uses the faster assembly
return switch (this.meta.is_tiny_string) {
1 => this.remainder_buf[0..this.meta.remainder_len],
@@ -818,23 +821,23 @@ pub fn startsWithGeneric(comptime T: type, self: []const T, str: []const T) bool
return eqlLong(bun.reinterpretSlice(u8, self[0..str.len]), bun.reinterpretSlice(u8, str[0..str.len]), false);
}
pub inline fn endsWith(self: string, str: string) bool {
pub fn endsWith(self: string, str: string) callconv(bun.callconv_inline) bool {
return str.len == 0 or @call(bun.callmod_inline, std.mem.endsWith, .{ u8, self, str });
}
pub inline fn endsWithComptime(self: string, comptime str: anytype) bool {
pub fn endsWithComptime(self: string, comptime str: anytype) callconv(bun.callconv_inline) bool {
return self.len >= str.len and eqlComptimeIgnoreLen(self[self.len - str.len .. self.len], comptime str);
}
pub inline fn startsWithChar(self: string, char: u8) bool {
pub fn startsWithChar(self: string, char: u8) callconv(bun.callconv_inline) bool {
return self.len > 0 and self[0] == char;
}
pub inline fn endsWithChar(self: string, char: u8) bool {
pub fn endsWithChar(self: string, char: u8) callconv(bun.callconv_inline) bool {
return self.len > 0 and self[self.len - 1] == char;
}
pub inline fn endsWithCharOrIsZeroLength(self: string, char: u8) bool {
pub fn endsWithCharOrIsZeroLength(self: string, char: u8) callconv(bun.callconv_inline) bool {
return self.len == 0 or self[self.len - 1] == char;
}
@@ -1014,7 +1017,13 @@ pub fn hasSuffixComptime(self: string, comptime alt: anytype) bool {
return self.len >= alt.len and eqlComptimeCheckLenWithType(u8, self[self.len - alt.len ..], alt, false);
}
fn eqlComptimeCheckLenU8(a: []const u8, comptime b: []const u8, comptime check_len: bool) bool {
const eqlComptimeCheckLenU8 = if (bun.Environment.isDebug) eqlComptimeDebugRuntimeFallback else eqlComptimeCheckLenU8Impl;
fn eqlComptimeDebugRuntimeFallback(a: []const u8, b: []const u8, check_len: bool) bool {
return std.mem.eql(u8, if (check_len) a else a.ptr[0..b.len], b);
}
fn eqlComptimeCheckLenU8Impl(a: []const u8, comptime b: []const u8, comptime check_len: bool) bool {
@setEvalBranchQuota(9999);
if (comptime check_len) {
@@ -1091,7 +1100,7 @@ pub fn eqlCaseInsensitiveASCII(a: string, b: string, comptime check_len: bool) b
bun.unsafeAssert(b.len > 0);
bun.unsafeAssert(a.len > 0);
return bun.C.strncasecmp(a.ptr, b.ptr, a.len) == 0;
return bun.c.strncasecmp(a.ptr, b.ptr, a.len) == 0;
}
pub fn eqlCaseInsensitiveT(comptime T: type, a: []const T, b: []const u8) bool {
@@ -1192,7 +1201,7 @@ pub fn eqlLong(a_str: string, b_str: string, comptime check_len: bool) bool {
return true;
}
pub inline fn append(allocator: std.mem.Allocator, self: string, other: string) ![]u8 {
pub fn append(allocator: std.mem.Allocator, self: string, other: string) callconv(bun.callconv_inline) ![]u8 {
var buf = try allocator.alloc(u8, self.len + other.len);
if (self.len > 0)
@memcpy(buf[0..self.len], self);
@@ -1201,7 +1210,7 @@ pub inline fn append(allocator: std.mem.Allocator, self: string, other: string)
return buf;
}
pub inline fn concatAllocT(comptime T: type, allocator: std.mem.Allocator, strs: anytype) ![]T {
pub fn concatAllocT(comptime T: type, allocator: std.mem.Allocator, strs: anytype) callconv(bun.callconv_inline) ![]T {
const buf = try allocator.alloc(T, len: {
var len: usize = 0;
inline for (strs) |s| {
@@ -1215,7 +1224,7 @@ pub inline fn concatAllocT(comptime T: type, allocator: std.mem.Allocator, strs:
};
}
pub inline fn concatBufT(comptime T: type, out: []T, strs: anytype) ![]T {
pub fn concatBufT(comptime T: type, out: []T, strs: anytype) callconv(bun.callconv_inline) ![]T {
var remain = out;
var n: usize = 0;
inline for (strs) |s| {
@@ -1257,7 +1266,7 @@ pub fn toUTF8AllocZ(allocator: std.mem.Allocator, js: []const u16) ![:0]u8 {
return list.items[0 .. list.items.len - 1 :0];
}
pub inline fn appendUTF8MachineWordToUTF16MachineWord(output: *[@sizeOf(usize) / 2]u16, input: *const [@sizeOf(usize) / 2]u8) void {
pub fn appendUTF8MachineWordToUTF16MachineWord(output: *[@sizeOf(usize) / 2]u16, input: *const [@sizeOf(usize) / 2]u8) callconv(bun.callconv_inline) void {
output[0 .. @sizeOf(usize) / 2].* = @as(
[4]u16,
@bitCast(@as(
@@ -1267,7 +1276,7 @@ pub inline fn appendUTF8MachineWordToUTF16MachineWord(output: *[@sizeOf(usize) /
);
}
pub inline fn copyU8IntoU16(output_: []u16, input_: []const u8) void {
pub fn copyU8IntoU16(output_: []u16, input_: []const u8) callconv(bun.callconv_inline) void {
const output = output_;
const input = input_;
if (comptime Environment.allow_assert) assert(input.len <= output.len);
@@ -1310,7 +1319,7 @@ pub fn copyU8IntoU16WithAlignment(comptime alignment: u21, output_: []align(alig
}
}
// pub inline fn copy(output_: []u8, input_: []const u8) void {
// pub fn copy(output_: []u8, input_: []const u8) callconv(bun.callconv_inline) void {
// var output = output_;
// var input = input_;
// if (comptime Environment.allow_assert) assert(input.len <= output.len);
@@ -1445,7 +1454,7 @@ pub const BOM = enum {
pub fn removeAndConvertToUTF8AndFree(bom: BOM, allocator: std.mem.Allocator, bytes: []u8) ![]u8 {
switch (bom) {
.utf8 => {
bun.C.memmove(bytes.ptr, bytes.ptr + utf8_bytes.len, bytes.len - utf8_bytes.len);
_ = bun.c.memmove(bytes.ptr, bytes.ptr + utf8_bytes.len, bytes.len - utf8_bytes.len);
return bytes[0 .. bytes.len - utf8_bytes.len];
},
.utf16_le => {
@@ -1458,7 +1467,7 @@ pub const BOM = enum {
else => {
// TODO: this needs to re-encode, for now we just remove the BOM
const bom_bytes = bom.getHeader();
bun.C.memmove(bytes.ptr, bytes.ptr + bom_bytes.len, bytes.len - bom_bytes.len);
_ = bun.c.memmove(bytes.ptr, bytes.ptr + bom_bytes.len, bytes.len - bom_bytes.len);
return bytes[0 .. bytes.len - bom_bytes.len];
},
}
@@ -2795,12 +2804,12 @@ pub fn escapeHTMLForLatin1Input(allocator: std.mem.Allocator, latin1: []const u8
break :brk values;
};
inline fn appendString(buf: [*]u8, comptime str: []const u8) usize {
fn appendString(buf: [*]u8, comptime str: []const u8) callconv(bun.callconv_inline) usize {
buf[0..str.len].* = str[0..str.len].*;
return str.len;
}
pub inline fn append(buf: [*]u8, char: u8) usize {
pub fn append(buf: [*]u8, char: u8) callconv(bun.callconv_inline) usize {
if (lengths[char] == 1) {
buf[0] = char;
return 1;
@@ -2816,7 +2825,7 @@ pub fn escapeHTMLForLatin1Input(allocator: std.mem.Allocator, latin1: []const u8
};
}
pub inline fn push(comptime len: anytype, chars_: *const [len]u8, allo: std.mem.Allocator) Escaped(u8) {
pub fn push(comptime len: anytype, chars_: *const [len]u8, allo: std.mem.Allocator) callconv(bun.callconv_inline) Escaped(u8) {
const chars = chars_.*;
var total: usize = 0;
@@ -3902,28 +3911,28 @@ pub fn isAllASCII(slice: []const u8) bool {
}
// #define U16_LEAD(supplementary) (UChar)(((supplementary)>>10)+0xd7c0)
pub inline fn u16Lead(supplementary: anytype) u16 {
pub fn u16Lead(supplementary: anytype) callconv(bun.callconv_inline) u16 {
return @intCast((supplementary >> 10) + 0xd7c0);
}
// #define U16_TRAIL(supplementary) (UChar)(((supplementary)&0x3ff)|0xdc00)
pub inline fn u16Trail(supplementary: anytype) u16 {
pub fn u16Trail(supplementary: anytype) callconv(bun.callconv_inline) u16 {
return @intCast((supplementary & 0x3ff) | 0xdc00);
}
// #define U16_IS_TRAIL(c) (((c)&0xfffffc00)==0xdc00)
pub inline fn u16IsTrail(supplementary: u16) bool {
pub fn u16IsTrail(supplementary: u16) callconv(bun.callconv_inline) bool {
return (@as(u32, @intCast(supplementary)) & 0xfffffc00) == 0xdc00;
}
// #define U16_IS_LEAD(c) (((c)&0xfffffc00)==0xd800)
pub inline fn u16IsLead(supplementary: u16) bool {
pub fn u16IsLead(supplementary: u16) callconv(bun.callconv_inline) bool {
return (@as(u32, @intCast(supplementary)) & 0xfffffc00) == 0xd800;
}
// #define U16_GET_SUPPLEMENTARY(lead, trail) \
// (((UChar32)(lead)<<10UL)+(UChar32)(trail)-U16_SURROGATE_OFFSET)
pub inline fn u16GetSupplementary(lead: u32, trail: u32) u32 {
pub fn u16GetSupplementary(lead: u32, trail: u32) callconv(bun.callconv_inline) u32 {
const shifted = lead << 10;
return (shifted + trail) - u16_surrogate_offset;
}
@@ -4169,7 +4178,7 @@ pub fn decodeHexToBytesTruncate(destination: []u8, comptime Char: type, source:
return _decodeHexToBytes(destination, Char, source, true) catch 0;
}
inline fn _decodeHexToBytes(destination: []u8, comptime Char: type, source: []const Char, comptime truncate: bool) !usize {
fn _decodeHexToBytes(destination: []u8, comptime Char: type, source: []const Char, comptime truncate: bool) callconv(bun.callconv_inline) !usize {
var remain = destination;
var input = source;
@@ -4661,7 +4670,7 @@ pub fn join(slices: []const string, delimiter: string, allocator: std.mem.Alloca
pub fn order(a: []const u8, b: []const u8) std.math.Order {
const len = @min(a.len, b.len);
const cmp = if (comptime Environment.isNative) bun.C.memcmp(a.ptr, b.ptr, len) else return std.mem.order(u8, a, b);
const cmp = if (comptime Environment.isNative) bun.c.memcmp(a.ptr, b.ptr, len) else return std.mem.order(u8, a, b);
return switch (std.math.sign(cmp)) {
0 => std.math.order(a.len, b.len),
1 => .gt,
@@ -4869,7 +4878,7 @@ pub fn NewCodePointIterator(comptime CodePointType_: type, comptime zeroValue: c
return true;
}
inline fn nextCodepointSlice(it: *Iterator) []const u8 {
fn nextCodepointSlice(it: *Iterator) callconv(bun.callconv_inline) []const u8 {
const bytes = it.bytes;
const prev = it.i;
const next_ = prev + it.next_width;
@@ -5294,15 +5303,15 @@ pub fn convertUTF16toUTF8InBuffer(
return buf[0..result];
}
pub inline fn charIsAnySlash(char: u8) bool {
pub fn charIsAnySlash(char: u8) callconv(bun.callconv_inline) bool {
return char == '/' or char == '\\';
}
pub inline fn startsWithWindowsDriveLetter(s: []const u8) bool {
pub fn startsWithWindowsDriveLetter(s: []const u8) callconv(bun.callconv_inline) bool {
return startsWithWindowsDriveLetterT(u8, s);
}
pub inline fn startsWithWindowsDriveLetterT(comptime T: type, s: []const T) bool {
pub fn startsWithWindowsDriveLetterT(comptime T: type, s: []const T) callconv(bun.callconv_inline) bool {
return s.len > 2 and s[1] == ':' and switch (s[0]) {
'a'...'z', 'A'...'Z' => true,
else => false,
@@ -6162,7 +6171,7 @@ fn QuoteEscapeFormat(comptime flags: QuoteEscapeFormatFlags) type {
}
/// Generic. Works on []const u8, []const u16, etc
pub inline fn indexOfScalar(input: anytype, scalar: std.meta.Child(@TypeOf(input))) ?usize {
pub fn indexOfScalar(input: anytype, scalar: std.meta.Child(@TypeOf(input))) callconv(bun.callconv_inline) ?usize {
if (comptime std.meta.Child(@TypeOf(input)) == u8) {
return strings.indexOfCharUsize(input, scalar);
} else {