diff options
author | 2021-10-16 20:23:37 -0700 | |
---|---|---|
committer | 2021-10-16 20:23:37 -0700 | |
commit | fd6d93292c1d3be28df35e46ab1833b42094472f (patch) | |
tree | adf472efedeb779c4dcfa255d2dd34dbe5b81c75 | |
parent | 9000165718791c22de2da7bf391b4d67c59b4976 (diff) | |
download | bun-fd6d93292c1d3be28df35e46ab1833b42094472f.tar.gz bun-fd6d93292c1d3be28df35e46ab1833b42094472f.tar.zst bun-fd6d93292c1d3be28df35e46ab1833b42094472f.zip |
more strings
-rw-r--r-- | src/runtime.version | 2 | ||||
-rw-r--r-- | src/string_immutable.zig | 29 |
2 files changed, 28 insertions, 3 deletions
diff --git a/src/runtime.version b/src/runtime.version index 8456f0e52..6eb1fbb2a 100644 --- a/src/runtime.version +++ b/src/runtime.version @@ -1 +1 @@ -4865dbe641dca1de
\ No newline at end of file +d0564ad3b9e88744
\ No newline at end of file diff --git a/src/string_immutable.zig b/src/string_immutable.zig index c9168d336..09b399633 100644 --- a/src/string_immutable.zig +++ b/src/string_immutable.zig @@ -268,6 +268,14 @@ pub fn quotedAlloc(allocator: *std.mem.Allocator, self: string) !string { return out; } +pub fn eqlAnyComptime(self: string, comptime list: []const string) bool { + inline for (list) |item| { + if (eqlComptimeCheckLen(self, item, true)) return true; + } + + return false; +} + pub fn endsWithAnyComptime(self: string, comptime str: string) bool { if (comptime str.len < 10) { const last = self[self.len - 1]; @@ -396,14 +404,32 @@ inline fn eqlComptimeCheckLen(self: string, comptime alt: anytype, comptime chec std.mem.readIntNative(u64, self[8..16]) and alt[16] == self[16]; }, + 18 => { + const first = comptime std.mem.readIntNative(u64, alt[0..8]); + const second = comptime std.mem.readIntNative(u64, alt[8..16]); + const third = comptime std.mem.readIntNative(u16, alt[16..18]); + return ((comptime !check_len) or self.len == alt.len) and + first == std.mem.readIntNative(u64, self[0..8]) and second == + std.mem.readIntNative(u64, self[8..16]) and + std.mem.readIntNative(u16, self[16..18]) == third; + }, 23 => { const first = comptime std.mem.readIntNative(u64, alt[0..8]); - const second = comptime std.mem.readIntNative(u64, alt[8..15]); + const second = comptime std.mem.readIntNative(u64, alt[8..16]); return ((comptime !check_len) or self.len == alt.len) and first == std.mem.readIntNative(u64, self[0..8]) and second == std.mem.readIntNative(u64, self[8..16]) and eqlComptimeIgnoreLen(self[16..23], comptime alt[16..23]); }, + 22 => { + const first = comptime std.mem.readIntNative(u64, alt[0..8]); + const second = comptime std.mem.readIntNative(u64, alt[8..16]); + + return ((comptime !check_len) or self.len == alt.len) and + first == std.mem.readIntNative(u64, self[0..8]) and + second == std.mem.readIntNative(u64, self[8..16]) and + eqlComptimeIgnoreLen(self[16..22], comptime alt[16..22]); + }, 24 => { const first = comptime std.mem.readIntNative(u64, alt[0..8]); const second = comptime std.mem.readIntNative(u64, alt[8..16]); @@ -668,7 +694,6 @@ pub fn toASCIIHexValue(character: u8) u8 { } pub fn utf8ByteSequenceLength(first_byte: u8) u3 { - // The switch is optimized much better than a "smart" approach using @clz return switch (first_byte) { 0b0000_0000...0b0111_1111 => 1, 0b1100_0000...0b1101_1111 => 2, |