aboutsummaryrefslogtreecommitdiff
path: root/src/string_immutable.zig
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-08-25 18:52:58 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-08-25 18:53:20 -0700
commit950d03a9ea8aed3eccca7e2cee3a9d0b0a0e3436 (patch)
treeffcb54b3fc098160ca29a42566d88d3cb0892b1b /src/string_immutable.zig
parente6a1209c53adb3056263b894d774b30ee70a3188 (diff)
downloadbun-950d03a9ea8aed3eccca7e2cee3a9d0b0a0e3436.tar.gz
bun-950d03a9ea8aed3eccca7e2cee3a9d0b0a0e3436.tar.zst
bun-950d03a9ea8aed3eccca7e2cee3a9d0b0a0e3436.zip
Fix incorrect `indexOfNotChar` causing sourcemaps bugs
Diffstat (limited to '')
-rw-r--r--src/string_immutable.zig16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/string_immutable.zig b/src/string_immutable.zig
index aaee55319..8503d3418 100644
--- a/src/string_immutable.zig
+++ b/src/string_immutable.zig
@@ -2829,7 +2829,7 @@ pub fn indexOfNotChar(slice: []const u8, char: u8) ?u32 {
while (remaining.len >= ascii_vector_size) {
const vec: AsciiVector = remaining[0..ascii_vector_size].*;
const cmp = @splat(ascii_vector_size, char) != vec;
- if (@reduce(.Min, @bitCast(AsciiVectorU1, cmp)) > 0) {
+ if (@reduce(.Max, @bitCast(AsciiVectorU1, cmp)) > 0) {
const bitmask = @ptrCast(*const AsciiVectorInt, &cmp).*;
const first = @ctz(AsciiVectorInt, bitmask);
return @as(u32, first) + @intCast(u32, slice.len - remaining.len);
@@ -3117,12 +3117,14 @@ pub fn @"nextUTF16NonASCIIOr$`\\"(
test "indexOfNotChar" {
{
- const yes = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
- try std.testing.expectEqual(indexOfNotChar(yes, 'a').?, 36);
- }
- {
- const yes = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
- try std.testing.expectEqual(indexOfNotChar(yes, 'a').?, 108);
+ var yes: [312]u8 = undefined;
+ var i: usize = 0;
+ while (i < yes.len) {
+ @memset(&yes, 'a', yes.len);
+ yes[i] = 'b';
+ assert(indexOfNotChar(&yes, 'a').? == i);
+ i += 1;
+ }
}
}