diff options
author | 2021-12-31 15:07:14 -0800 | |
---|---|---|
committer | 2021-12-31 15:07:14 -0800 | |
commit | d7c69d3b783d7dff7f3f44fce7d38d7dde4ecfcc (patch) | |
tree | 9ea6f63e27c56eeef736e01592d36f4f1403ab85 /src/string_immutable.zig | |
parent | 059aa425b793f4f4c79fccaa9c42b0b9329e9fb0 (diff) | |
download | bun-d7c69d3b783d7dff7f3f44fce7d38d7dde4ecfcc.tar.gz bun-d7c69d3b783d7dff7f3f44fce7d38d7dde4ecfcc.tar.zst bun-d7c69d3b783d7dff7f3f44fce7d38d7dde4ecfcc.zip |
Add unrolled case insensitive string comparison
Diffstat (limited to '')
-rw-r--r-- | src/string_immutable.zig | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/string_immutable.zig b/src/string_immutable.zig index 8b6215606..2796f59b8 100644 --- a/src/string_immutable.zig +++ b/src/string_immutable.zig @@ -413,6 +413,27 @@ inline fn eqlComptimeCheckLen(a: string, comptime b: anytype, comptime check_len return true; } +pub fn eqlCaseInsensitiveASCII(a: string, comptime b: anytype, comptime check_len: bool) bool { + if (comptime check_len) { + if (comptime b.len == 0) { + return a.len == 0; + } + + switch (a.len) { + b.len => void{}, + else => return false, + } + } + + // pray to the auto vectorization gods + inline for (b) |c, i| { + const char = comptime std.ascii.toLower(c); + if (char != std.ascii.toLower(a[i])) return false; + } + + return true; +} + pub fn eqlLong(a_: string, b: string, comptime check_len: bool) bool { if (comptime check_len) { if (a_.len == 0) { |