From 3413cf6348374dffc35008cf966ea7846fe8edb5 Mon Sep 17 00:00:00 2001 From: fubark Date: Mon, 29 Jul 2024 15:26:45 -0400 Subject: [PATCH] Fix simd getLineEnd. --- src/string.zig | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/string.zig b/src/string.zig index 357d50297..698a7e1c3 100644 --- a/src/string.zig +++ b/src/string.zig @@ -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."); } } }