authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-19 12:05:40-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-19 12:07:32-07:00
loge6e8cacab904f10d6e5a773867826570783d0bf4
tree3485c42eb335dd5f3bde6c4ac540cdbd2456ada5
parent32cb9462ffa0a9df7a080d67eaf3a5762173f742

std.mem.order: use for loop syntax

Not only does it look nicer, it's a performance enhancement for debug builds since the safety checks are eliminated.

1 files changed, 2 insertions(+), 3 deletions(-)

lib/std/mem.zig+2-3
......@@ -597,9 +597,8 @@ pub fn sortUnstableContext(a: usize, b: usize, context: anytype) void {
597597/// Compares two slices of numbers lexicographically. O(n).
598598pub fn order(comptime T: type, lhs: []const T, rhs: []const T) math.Order {
599599 const n = @min(lhs.len, rhs.len);
600 var i: usize = 0;
601 while (i < n) : (i += 1) {
602 switch (math.order(lhs[i], rhs[i])) {
600 for (lhs[0..n], rhs[0..n]) |lhs_elem, rhs_elem| {
601 switch (math.order(lhs_elem, rhs_elem)) {
603602 .eq => continue,
604603 .lt => return .lt,
605604 .gt => return .gt,