Skip to content

Commit

Permalink
Fix simd getLineEnd.
Browse files Browse the repository at this point in the history
  • Loading branch information
fubark committed Jul 29, 2024
1 parent 8ff321d commit 3413cf6
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/string.zig
Original file line number Diff line number Diff line change
Expand Up @@ -684,17 +684,19 @@ pub fn getLineEnd(buf: []const u8) ?usize {
const lfHits: MaskInt = @bitCast(vbuf == lfNeedle);
const crHits: MaskInt = @bitCast(vbuf == crNeedle);
const bitIdx = @ctz(lfHits | crHits);
if (bitIdx > 0) {
if (bitIdx < VecSize) {
// Found.
const res = i + bitIdx;
if (buf[res] == '\n') {
return res + 1;
} else {
} else if (buf[res] == '\r') {
if (res + 1 < buf.len and buf[res+1] == '\n') {
return res + 2;
} else {
return res + 1;
}
} else {
@panic("Unexpected.");
}
}
}
Expand Down

0 comments on commit 3413cf6

Please sign in to comment.