authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-08-13 18:41:53-07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-08-13 18:41:53-07:00
log88b94a1960be841bb93a0bca65d556cb6385d1fd
tree6496989729ae2895eec7c271b1832cb0dc69a62b
parentdaa45d99dc3eac1f38b0f3f4c138483f310860a0
signature Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

add Object.order_bare()


1 files changed, 15 insertions(+), 8 deletions(-)

git.zig+15-8
...@@ -1909,9 +1909,18 @@ pub const Tree = struct {...@@ -1909,9 +1909,18 @@ pub const Tree = struct {
1909 }1909 }
19101910
1911 pub fn order(lhs: Object, rhs: Object) std.math.Order {1911 pub fn order(lhs: Object, rhs: Object) std.math.Order {
1912 if (lhs.name.ptr != rhs.name.ptr) {1912 return order_bare(
1913 const n = @min(lhs.name.len, rhs.name.len);1913 lhs.name,
1914 for (lhs.name[0..n], rhs.name[0..n]) |lhs_elem, rhs_elem| {1914 rhs.name,
1915 lhs.mode.type == .directory,
1916 rhs.mode.type == .directory,
1917 );
1918 }
1919
1920 pub fn order_bare(l: []const u8, r: []const u8, l_is_dir: bool, r_is_dir: bool) std.math.Order {
1921 if (l.ptr != r.ptr) {
1922 const n = @min(l.len, r.len);
1923 for (l[0..n], r[0..n]) |lhs_elem, rhs_elem| {
1915 switch (std.math.order(lhs_elem, rhs_elem)) {1924 switch (std.math.order(lhs_elem, rhs_elem)) {
1916 .eq => continue,1925 .eq => continue,
1917 .lt => return .lt,1926 .lt => return .lt,
...@@ -1919,11 +1928,9 @@ pub const Tree = struct {...@@ -1919,11 +1928,9 @@ pub const Tree = struct {
1919 }1928 }
1920 }1929 }
1921 }1930 }
1922 const l_is_dir = lhs.mode.type == .directory;1931 return switch (std.math.order(l.len, r.len)) {
1923 const r_is_dir = rhs.mode.type == .directory;1932 .lt => if (l_is_dir) std.math.order('/', r[l.len]) else .lt,
1924 return switch (std.math.order(lhs.name.len, rhs.name.len)) {1933 .gt => if (r_is_dir) std.math.order(l[r.len], '/') else .gt,
1925 .lt => if (l_is_dir) std.math.order('/', rhs.name[lhs.name.len]) else .lt,
1926 .gt => if (r_is_dir) std.math.order(lhs.name[rhs.name.len], '/') else .gt,
1927 .eq => if (l_is_dir and r_is_dir) .eq else if (l_is_dir) .gt else if (r_is_dir) .lt else .eq,1934 .eq => if (l_is_dir and r_is_dir) .eq else if (l_is_dir) .gt else if (r_is_dir) .lt else .eq,
1928 };1935 };
1929 }1936 }