Refactor Zig imports and file structure (part 1) (#21270)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
taylor.fish
2025-07-22 17:51:38 -07:00
committed by GitHub
parent 73d92c7518
commit 07cd45deae
564 changed files with 9917 additions and 9697 deletions

View File

@@ -345,7 +345,7 @@ pub const BufferedWriter = struct {
return pending.len;
}
const E = bun.JSAst.E;
const E = bun.ast.E;
/// Write a E.String to the buffer.
/// This automatically encodes UTF-16 into UTF-8 using
@@ -455,10 +455,11 @@ pub fn writeAll(self: *MutableString, bytes: string) Allocator.Error!usize {
return bytes.len;
}
const string = []const u8;
const std = @import("std");
const Allocator = std.mem.Allocator;
const bun = @import("bun");
const js_lexer = bun.js_lexer;
const string = bun.string;
const strings = bun.strings;

View File

@@ -14,7 +14,7 @@ pub const PathString = packed struct(PathStringBackingIntType) {
ptr: PointerIntType = 0,
len: PathInt = 0,
const JSC = bun.JSC;
const jsc = bun.jsc;
pub fn estimatedSize(this: *const PathString) usize {
return @as(usize, this.len);

View File

@@ -266,7 +266,8 @@ test "Creating an inlined SmolStr does not allocate" {
try t.expect(hello.isInlined());
}
const BabyList = @import("../baby_list.zig").BabyList;
const bun = @import("bun");
const BabyList = bun.collections.BabyList;
const std = @import("std");
const t = std.testing;

View File

@@ -87,7 +87,7 @@ pub const WTFStringImplStruct = extern struct {
}
pub inline fn deref(self: WTFStringImpl) void {
JSC.markBinding(@src());
jsc.markBinding(@src());
const current_count = self.refCount();
bun.assert(self.hasAtLeastOneRef()); // do not use current_count, it breaks for static strings
bun.cpp.Bun__WTFStringImpl__deref(self);
@@ -99,7 +99,7 @@ pub const WTFStringImplStruct = extern struct {
}
pub inline fn ref(self: WTFStringImpl) void {
JSC.markBinding(@src());
jsc.markBinding(@src());
const current_count = self.refCount();
bun.assert(self.hasAtLeastOneRef()); // do not use current_count, it breaks for static strings
bun.cpp.Bun__WTFStringImpl__ref(self);
@@ -118,7 +118,7 @@ pub const WTFStringImplStruct = extern struct {
/// Compute the hash() if necessary
pub fn ensureHash(this: WTFStringImpl) void {
JSC.markBinding(@src());
jsc.markBinding(@src());
bun.cpp.Bun__WTFStringImpl__ensureHash(this);
}
@@ -197,7 +197,7 @@ pub const WTFStringImplStruct = extern struct {
pub fn utf8ByteLength(this: WTFStringImpl) usize {
if (this.is8Bit()) {
const input = this.latin1Slice();
return if (input.len > 0) JSC.WebCore.encoding.byteLengthU8(input.ptr, input.len, .utf8) else 0;
return if (input.len > 0) jsc.WebCore.encoding.byteLengthU8(input.ptr, input.len, .utf8) else 0;
} else {
const input = this.utf16Slice();
return if (input.len > 0) bun.strings.elementLengthUTF16IntoUTF8([]const u16, input) else 0;
@@ -260,5 +260,5 @@ pub const StringImplAllocator = struct {
const bun = @import("bun");
const std = @import("std");
const JSC = bun.JSC;
const ZigString = bun.JSC.ZigString;
const jsc = bun.jsc;
const ZigString = bun.jsc.ZigString;

2363
src/string/immutable.zig Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,72 @@
pub fn ExactSizeMatcher(comptime max_bytes: usize) type {
switch (max_bytes) {
1, 2, 4, 8, 12, 16 => {},
else => {
@compileError("max_bytes must be 1, 2, 4, 8, 12, or 16.");
},
}
const T = std.meta.Int(
.unsigned,
max_bytes * 8,
);
return struct {
pub fn match(str: anytype) T {
switch (str.len) {
1...max_bytes - 1 => {
var tmp: [max_bytes]u8 = undefined;
@memcpy(tmp[0..str.len], str);
@memset(tmp[str.len..], 0);
return std.mem.readInt(T, &tmp, .little);
},
max_bytes => {
return std.mem.readInt(T, str[0..max_bytes], .little);
},
0 => {
return 0;
},
else => {
return std.math.maxInt(T);
},
}
}
pub fn matchLower(str: anytype) T {
switch (str.len) {
1...max_bytes - 1 => {
var tmp: [max_bytes]u8 = undefined;
for (str, 0..) |char, i| {
tmp[i] = std.ascii.toLower(char);
}
@memset(tmp[str.len..], 0);
return std.mem.readInt(T, &tmp, .little);
},
max_bytes => {
return std.mem.readInt(T, str[0..max_bytes], .little);
},
0 => {
return 0;
},
else => {
return std.math.maxInt(T);
},
}
}
pub fn case(comptime str: []const u8) T {
if (str.len < max_bytes) {
var bytes = std.mem.zeroes([max_bytes]u8);
bytes[0..str.len].* = str[0..str.len].*;
return std.mem.readInt(T, &bytes, .little);
} else if (str.len == max_bytes) {
return std.mem.readInt(T, str[0..str.len], .little);
} else {
@compileError("str: \"" ++ str ++ "\" too long");
}
}
};
}
const std = @import("std");

File diff suppressed because it is too large Load Diff