diff options
author | 2023-02-04 00:30:37 -0800 | |
---|---|---|
committer | 2023-02-04 00:30:37 -0800 | |
commit | bd4d8bdb6a7fa3a67a0e7efee3fa375b831317b7 (patch) | |
tree | f0ecf59377851c611c2981757cac9019a7d4876e /src/string_immutable.zig | |
parent | 31c5c2fb3693378438384f3d06e1e579184c8067 (diff) | |
download | bun-bd4d8bdb6a7fa3a67a0e7efee3fa375b831317b7.tar.gz bun-bd4d8bdb6a7fa3a67a0e7efee3fa375b831317b7.tar.zst bun-bd4d8bdb6a7fa3a67a0e7efee3fa375b831317b7.zip |
Faster string sorting
Diffstat (limited to 'src/string_immutable.zig')
-rw-r--r-- | src/string_immutable.zig | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/string_immutable.zig b/src/string_immutable.zig index 55e7f9225..caf09ae02 100644 --- a/src/string_immutable.zig +++ b/src/string_immutable.zig @@ -3783,12 +3783,23 @@ pub fn join(slices: []const string, delimiter: string, allocator: std.mem.Alloca return try std.mem.join(allocator, delimiter, slices); } +pub fn order(a: []const u8, b: []const u8) std.math.Order { + const len = @min(a.len, b.len); + const cmp = bun.C.memcmp(a.ptr, b.ptr, len); + return switch (cmp) { + 0 => std.math.order(a.len, b.len), + 1 => .gt, + -1 => .lt, + else => unreachable, + }; +} + pub fn cmpStringsAsc(_: void, a: string, b: string) bool { - return std.mem.order(u8, a, b) == .lt; + return order(a, b) == .lt; } pub fn cmpStringsDesc(_: void, a: string, b: string) bool { - return std.mem.order(u8, a, b) == .gt; + return order(a, b) == .gt; } const sort_asc = std.sort.asc(u8); |