aboutsummaryrefslogtreecommitdiff
path: root/src/string_immutable.zig
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-02-25 18:22:29 -0800
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-02-25 18:23:01 -0800
commit693be3d1c2fe63cb5961a0023ad4c301209495bc (patch)
treec56159b91e01438a416b5b10dc114f9f51fef61a /src/string_immutable.zig
parent8ba65a4f0bbd38b5c6a677d93d1fa13d0042bb35 (diff)
downloadbun-693be3d1c2fe63cb5961a0023ad4c301209495bc.tar.gz
bun-693be3d1c2fe63cb5961a0023ad4c301209495bc.tar.zst
bun-693be3d1c2fe63cb5961a0023ad4c301209495bc.zip
Faster `eqlCaseInsensitiveASCII`
Diffstat (limited to 'src/string_immutable.zig')
-rw-r--r--src/string_immutable.zig34
1 files changed, 20 insertions, 14 deletions
diff --git a/src/string_immutable.zig b/src/string_immutable.zig
index ea81de06c..e5a37006a 100644
--- a/src/string_immutable.zig
+++ b/src/string_immutable.zig
@@ -785,25 +785,31 @@ pub inline fn eqlComptimeCheckLenWithType(comptime Type: type, a: []const Type,
return eqlComptimeCheckLenWithKnownType(comptime Type, a, if (@typeInfo(@TypeOf(b)) != .Pointer) &b else b, comptime check_len);
}
-pub fn eqlCaseInsensitiveASCII(a: string, comptime b: anytype, comptime check_len: bool) bool {
+pub fn eqlCaseInsensitiveASCIIIgnoreLength(
+ a: string,
+ b: string,
+) bool {
+ return eqlCaseInsensitiveASCII(a, b, false);
+}
+
+pub fn eqlCaseInsensitiveASCIIICheckLength(
+ a: string,
+ b: string,
+) bool {
+ return eqlCaseInsensitiveASCII(a, b, true);
+}
+
+pub fn eqlCaseInsensitiveASCII(a: string, b: string, comptime check_len: bool) bool {
if (comptime check_len) {
- if (comptime b.len == 0) {
- return a.len == 0;
- }
+ if (a.len != b.len) return false;
- switch (a.len) {
- b.len => void{},
- else => return false,
- }
+ if (a.len == 0) return true;
}
- // pray to the auto vectorization gods
- inline for (b, 0..) |c, i| {
- const char = comptime std.ascii.toLower(c);
- if (char != std.ascii.toLower(a[i])) return false;
- }
+ std.debug.assert(b.len > 0);
+ std.debug.assert(a.len > 0);
- return true;
+ return bun.C.strncasecmp(a.ptr, b.ptr, a.len) == 0;
}
pub fn eqlLong(a_str: string, b_str: string, comptime check_len: bool) bool {