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