const std = @import("std"); pub const string = []const u8; pub const stringZ = [:0]const u8; pub const stringMutable = []u8; pub const CodePoint = i32; const bun = @import("./global.zig"); // macOS sets file path limit to 1024 // Since a pointer on x64 is 64 bits and only 46 bits are used // We can safely store the entire path slice in a single u64. pub const PathString = packed struct { const PathIntLen = std.math.IntFittingRange(0, bun.MAX_PATH_BYTES); pub const use_small_path_string = @bitSizeOf(usize) - @bitSizeOf(PathIntLen) >= 53; pub const PathInt = if (use_small_path_string) PathIntLen else usize; pub const PointerIntType = if (use_small_path_string) u53 else usize; ptr: PointerIntType = 0, len: PathInt = 0, const JSC = @import("javascript_core"); pub fn fromJS(value: JSC.JSValue, global: *JSC.JSGlobalObject, exception: JSC.C.ExceptionRef) PathString { if (!value.jsType().isStringLike()) { JSC.JSError(JSC.getAllocator(global.ref()), "Only path strings are supported for now", .{}, global.ref(), exception); return PathString{}; } var zig_str = JSC.ZigString.init(""); value.toZigString(&zig_str, global); return PathString.init(zig_str.slice()); } pub inline fn asRef(this: PathString) JSC.JSValueRef { return this.toValue().asObjectRef(); } pub fn toJS(this: PathString, ctx: JSC.C.JSContextRef, _: JSC.C.ExceptionRef) JSC.C.JSValueRef { var zig_str = JSC.ZigString.init(this.slice()); zig_str.detectEncoding(); return zig_str.toValueAuto(ctx.ptr()).asObjectRef(); } pub inline fn slice(this: anytype) string { @setRuntimeSafety(false); // "cast causes pointer to be null" is fine here. if it is null, the len will be 0. return @intToPtr([*]u8, @intCast(usize, this.ptr))[0..this.len]; } pub inline fn sliceAssumeZ(this: anytype) stringZ { @setRuntimeSafety(false); // "cast causes pointer to be null" is fine here. if it is null, the len will be 0. return @intToPtr([*:0]u8, @intCast(usize, this.ptr))[0..this.len]; } pub inline fn init(str: string) @This() { @setRuntimeSafety(false); // "cast causes pointer to be null" is fine here. if it is null, the len will be 0. return @This(){ .ptr = @truncate(PointerIntType, @ptrToInt(str.ptr)), .len = @truncate(PathInt, str.len), }; } pub inline fn isEmpty(this: anytype) bool { return this.len == 0; } pub const empty = @This(){ .ptr = 0, .len = 0 }; comptime { if (!bun.Environment.isWasm) { if (use_small_path_string and @bitSizeOf(@This()) != 64) { @compileError("PathString must be 64 bits"); } else if (!use_small_path_string and @bitSizeOf(@This()) != 128) { @compileError("PathString must be 128 bits"); } } } }; pub const HashedString = struct { ptr: [*]const u8, len: u32, hash: u32, pub const empty = HashedString{ .ptr = @intToPtr([*]const u8, 0xDEADBEEF), .len = 0, .hash = 0 }; pub fn init(buf: string) HashedString { return HashedString{ .ptr = buf.ptr, .len = @truncate(u32, buf.len), .hash = @truncate(u32, std.hash.Wyhash.hash(0, buf)), }; } pub fn initNoHash(buf: string) HashedString { return HashedString{ .ptr = buf.ptr, .len = @truncate(u32, buf.len), .hash = 0, }; } pub fn eql(this: HashedString, other: anytype) bool { return Eql(this, @TypeOf(other), other); } pub fn Eql(this: HashedString, comptime Other: type, other: Other) bool { switch (comptime Other) { HashedString, *HashedString, *const HashedString => { return ((@maximum(this.hash, other.hash) > 0 and this.hash == other.hash) or (this.ptr == other.ptr)) and this.len == other.len; }, else => { return @as(usize, this.len) == other.len and @truncate(u32, std.hash.Wyhash.hash(0, other[0..other.len])) == this.hash; }, } } pub fn str(this: HashedString) string { return this.ptr[0..this.len]; } }; on> Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
path: root/bench/snippets/realpath.mjs (unfollow)
AgeCommit message (Expand)AuthorFilesLines
2023-07-18add padding bytesGravatar Dylan Conway 1-1/+1
2023-07-18feature(constants) add constants/node:constants module and tests(prisma) use ...Gravatar Ciro Spaciari 16-20/+529
2023-07-18patch checkServerIdentity (#3671)Gravatar Ciro Spaciari 3-3/+9
2023-07-18Update workers.mdGravatar Jarred Sumner 1-2/+2
2023-07-18[jest] execute lifecycle hooks on empty blocks (#3663)Gravatar Alex Lam S.L 2-19/+79
2023-07-18ClarifyGravatar Jarred Sumner 1-0/+2
2023-07-18Fixes #3669Gravatar Jarred Sumner 4-13/+35
2023-07-18zig upgrade (#3667)Gravatar Dylan Conway 154-4894/+4857
2023-07-17Enable postgres prisma testGravatar Jarred Sumner 1-1/+1
2023-07-17Emit writeBarrier in `napi_module_register`Gravatar Jarred Sumner 1-6/+14
2023-07-17Fix potential crash in process.dlopen()Gravatar Jarred Sumner 2-5/+27
2023-07-17Implement `process.{stdout, stderr}.{columns, rows, getWindowSize}`Gravatar Jarred Sumner 4-32/+108
2023-07-17[tls] General compatibility improvements (#3596)Gravatar Ciro Spaciari 23-298/+2907
2023-07-17package json `main` field extension order (#3664)Gravatar Dylan Conway 3-3/+96
2023-07-17[install] handle duplicated workspace declarations gracefully (#3662)Gravatar Alex Lam S.L 2-6/+197
2023-07-17Clean up worker docsGravatar Colin McDonnell 1-65/+69
2023-07-17Tweak test docsGravatar Colin McDonnell 2-4/+3
2023-07-17workaround `readable-stream` compatibility (#3626)Gravatar Alex Lam S.L 3-4/+5
2023-07-17Fix flaky process testGravatar Jarred SUmner 1-2/+2
2023-07-17Fix test with incorrect textGravatar Jarred Sumner 1-3/+3
2023-07-17Fix incorrect nameGravatar Jarred Sumner 2-4/+4
2023-07-17Fix speculative crashes in console.log(formData) and console.log(headers)Gravatar Jarred Sumner 2-30/+24
2023-07-17Fix crash in console.log(urlSearchParams) on a URLSearchParams object with a ...Gravatar Jarred Sumner 2-4/+99
2023-07-17Fix memory leak in `await new Response(latin1String).arrayBuffer()` and `awai...Gravatar Jarred Sumner 16-102/+361
2023-07-1720% faster `deserialize` (#3655)Gravatar Jarred Sumner 2-12/+197
2023-07-16Document `--smol`Gravatar Jarred Sumner 1-70/+59
2023-07-16Add `--smol` to bunfigGravatar Jarred Sumner 1-0/+12
2023-07-16Document serialize/deserializeGravatar Jarred Sumner 1-0/+14