diff options
author | 2023-02-25 00:51:20 +0200 | |
---|---|---|
committer | 2023-02-24 14:51:20 -0800 | |
commit | 26df7ca8926c67311f5ca1fbfc04e2c374c3e1a3 (patch) | |
tree | f6b794c7ebc772bcd3e394b36a08b5c69ca215ff /src/string_immutable.zig | |
parent | d33a53deb0d9d2d0b8a586a72e666bb46a174a69 (diff) | |
download | bun-26df7ca8926c67311f5ca1fbfc04e2c374c3e1a3.tar.gz bun-26df7ca8926c67311f5ca1fbfc04e2c374c3e1a3.tar.zst bun-26df7ca8926c67311f5ca1fbfc04e2c374c3e1a3.zip |
fix `compiler_rt` linking failure on `x86_64` (#2163)
- minor code tweaks
Diffstat (limited to 'src/string_immutable.zig')
-rw-r--r-- | src/string_immutable.zig | 23 |
1 files changed, 7 insertions, 16 deletions
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" { |