aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build.zig10
-rw-r--r--src/bun.zig2
-rw-r--r--src/http_client_async.zig2
-rw-r--r--src/install/lockfile.zig63
-rw-r--r--src/string_immutable.zig23
5 files changed, 38 insertions, 62 deletions
diff --git a/build.zig b/build.zig
index fe8aa6a53..892140511 100644
--- a/build.zig
+++ b/build.zig
@@ -43,8 +43,6 @@ const color_map = std.ComptimeStringMap([]const u8, .{
&.{ "yellow", "33m" },
});
-var compiler_rt_path: []const u8 = "";
-var compiler_rt_path_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
fn addInternalPackages(b: *Build, step: *CompileStep, _: std.mem.Allocator, _: []const u8, target: anytype) !void {
var bun = b.createModule(.{
.source_file = FileSource.relative("src/bun_redirect.zig"),
@@ -313,9 +311,12 @@ pub fn build(b: *Build) !void {
obj.linkLibC();
obj.strip = false;
- obj.bundle_compiler_rt = true;
+ obj.bundle_compiler_rt = false;
obj.omit_frame_pointer = optimize != .Debug;
+ // Disable staack probing on x86 so we don't need to include compiler_rt
+ if (target.getCpuArch().isX86()) obj.disable_stack_probing = true;
+
if (b.option(bool, "for-editor", "Do not emit bin, just check for errors") orelse false) {
obj.emit_bin = .no_emit;
}
@@ -596,9 +597,6 @@ pub fn configureObjectStep(b: *std.build.Builder, obj: *CompileStep, comptime Ta
if (target.getOsTag() != .freestanding) obj.linkLibC();
if (target.getOsTag() != .freestanding) obj.bundle_compiler_rt = false;
- // Disable staack probing on x86 so we don't need to include compiler_rt
- if (target.getCpuArch().isX86()) obj.disable_stack_probing = true;
-
if (target.getOsTag() == .linux) {
// obj.want_lto = tar;
obj.link_emit_relocs = true;
diff --git a/src/bun.zig b/src/bun.zig
index df3d1a72f..17a234d5d 100644
--- a/src/bun.zig
+++ b/src/bun.zig
@@ -386,7 +386,7 @@ pub inline fn range(comptime min: anytype, comptime max: anytype) [max - min]usi
pub fn copy(comptime Type: type, dest: []Type, src: []const Type) void {
if (comptime Environment.allow_assert) std.debug.assert(dest.len >= src.len);
- if (src.ptr == dest.ptr) return;
+ if (@ptrToInt(src.ptr) == @ptrToInt(dest.ptr)) return;
var input: []const u8 = std.mem.sliceAsBytes(src);
var output: []u8 = std.mem.sliceAsBytes(dest);
diff --git a/src/http_client_async.zig b/src/http_client_async.zig
index 7060c3ed2..41684acde 100644
--- a/src/http_client_async.zig
+++ b/src/http_client_async.zig
@@ -1057,7 +1057,7 @@ pub fn hashHeaderName(name: string) u64 {
while (remain.len > 0) {
const end = @min(hasher.buf.len, remain.len);
- hasher.update(strings.copyLowercase(remain[0..end], &buf));
+ hasher.update(strings.copyLowercaseIfNeeded(remain[0..end], &buf));
remain = remain[end..];
}
diff --git a/src/install/lockfile.zig b/src/install/lockfile.zig
index c7009c57b..4e604fca5 100644
--- a/src/install/lockfile.zig
+++ b/src/install/lockfile.zig
@@ -1590,23 +1590,26 @@ pub const StringBuilder = struct {
pub inline fn count(this: *StringBuilder, slice: string) void {
if (String.canInline(slice)) return;
- return countWithHash(this, slice, String.Builder.stringHash(slice));
+ this._countWithHash(slice, String.Builder.stringHash(slice));
}
pub inline fn countWithHash(this: *StringBuilder, slice: string, hash: u64) void {
if (String.canInline(slice)) return;
+ this._countWithHash(slice, hash);
+ }
+
+ inline fn _countWithHash(this: *StringBuilder, slice: string, hash: u64) void {
if (!this.lockfile.string_pool.contains(hash)) {
this.cap += slice.len;
}
}
pub fn allocatedSlice(this: *StringBuilder) []const u8 {
- if (this.ptr == null) return "";
- return this.ptr.?[0..this.cap];
+ return if (this.ptr) |ptr| ptr[0..this.cap] else "";
}
pub fn clamp(this: *StringBuilder) void {
- std.debug.assert(this.cap >= this.len);
+ if (comptime Environment.allow_assert) std.debug.assert(this.cap >= this.len);
const excess = this.cap - this.len;
@@ -1631,15 +1634,11 @@ pub const StringBuilder = struct {
// SlicedString is not supported due to inline strings.
pub fn appendWithoutPool(this: *StringBuilder, comptime Type: type, slice: string, hash: u64) Type {
if (String.canInline(slice)) {
- switch (Type) {
- String => {
- return String.init(this.lockfile.buffers.string_bytes.items, slice);
- },
- ExternalString => {
- return ExternalString.init(this.lockfile.buffers.string_bytes.items, slice, hash);
- },
+ return switch (Type) {
+ String => String.init(this.lockfile.buffers.string_bytes.items, slice),
+ ExternalString => ExternalString.init(this.lockfile.buffers.string_bytes.items, slice, hash),
else => @compileError("Invalid type passed to StringBuilder"),
- }
+ };
}
if (comptime Environment.allow_assert) {
std.debug.assert(this.len <= this.cap); // didn't count everything
@@ -1652,28 +1651,20 @@ pub const StringBuilder = struct {
if (comptime Environment.allow_assert) std.debug.assert(this.len <= this.cap);
- switch (Type) {
- String => {
- return String.init(this.lockfile.buffers.string_bytes.items, final_slice);
- },
- ExternalString => {
- return ExternalString.init(this.lockfile.buffers.string_bytes.items, final_slice, hash);
- },
+ return switch (Type) {
+ String => String.init(this.lockfile.buffers.string_bytes.items, final_slice),
+ ExternalString => ExternalString.init(this.lockfile.buffers.string_bytes.items, final_slice, hash),
else => @compileError("Invalid type passed to StringBuilder"),
- }
+ };
}
pub fn appendWithHash(this: *StringBuilder, comptime Type: type, slice: string, hash: u64) Type {
if (String.canInline(slice)) {
- switch (Type) {
- String => {
- return String.init(this.lockfile.buffers.string_bytes.items, slice);
- },
- ExternalString => {
- return ExternalString.init(this.lockfile.buffers.string_bytes.items, slice, hash);
- },
+ return switch (Type) {
+ String => String.init(this.lockfile.buffers.string_bytes.items, slice),
+ ExternalString => ExternalString.init(this.lockfile.buffers.string_bytes.items, slice, hash),
else => @compileError("Invalid type passed to StringBuilder"),
- }
+ };
}
if (comptime Environment.allow_assert) {
@@ -1692,18 +1683,14 @@ pub const StringBuilder = struct {
if (comptime Environment.allow_assert) std.debug.assert(this.len <= this.cap);
- switch (Type) {
- String => {
- return string_entry.value_ptr.*;
- },
- ExternalString => {
- return ExternalString{
- .value = string_entry.value_ptr.*,
- .hash = hash,
- };
+ return switch (Type) {
+ String => string_entry.value_ptr.*,
+ ExternalString => .{
+ .value = string_entry.value_ptr.*,
+ .hash = hash,
},
else => @compileError("Invalid type passed to StringBuilder"),
- }
+ };
}
};
diff --git a/src/string_immutable.zig b/src/string_immutable.zig
index ee65d1224..ea81de06c 100644
--- a/src/string_immutable.zig
+++ b/src/string_immutable.zig
@@ -370,7 +370,7 @@ pub fn copyLowercase(in: string, out: []u8) string {
var in_slice = in;
var out_slice = out;
- begin: while (in_slice.len > 0) {
+ begin: while (true) {
for (in_slice, 0..) |c, i| {
switch (c) {
'A'...'Z' => {
@@ -393,18 +393,17 @@ pub fn copyLowercase(in: string, out: []u8) string {
}
pub fn copyLowercaseIfNeeded(in: string, out: []u8) string {
- var in_slice: string = in;
- var out_slice: []u8 = out[0..in.len];
+ var in_slice = in;
+ var out_slice = out;
var any = false;
- begin: while (out_slice.len > 0) {
+ begin: while (true) {
for (in_slice, 0..) |c, i| {
switch (c) {
'A'...'Z' => {
- @memcpy(out_slice.ptr, in_slice.ptr, i);
+ bun.copy(u8, out_slice, in_slice[0..i]);
out_slice[i] = std.ascii.toLower(c);
const end = i + 1;
- if (end >= out_slice.len) break :begin;
in_slice = in_slice[end..];
out_slice = out_slice[end..];
any = true;
@@ -414,19 +413,11 @@ pub fn copyLowercaseIfNeeded(in: string, out: []u8) string {
}
}
- if (!any) {
- return in;
- }
-
- @memcpy(out_slice.ptr, in_slice.ptr, in_slice.len);
+ if (any) bun.copy(u8, out_slice, in_slice);
break :begin;
}
- if (!any) {
- return in;
- }
-
- return out[0..in.len];
+ return if (any) out[0..in.len] else in;
}
test "indexOf" {