| ... | ... | @@ -1393,7 +1393,33 @@ pub const Tree = struct { |
| 1393 | 1393 | children: []const Object, |
| 1394 | 1394 | |
| 1395 | 1395 | pub fn get(self: Tree, name: string, hint: Object.Type) ?Object { |
| 1396 | | const i = std.sort.binarySearch(Object, self.children, .{ name, hint }, Object.search) orelse return null; |
| 1396 | _ = hint; |
| 1397 | // modified std.sort.binarySearch |
| 1398 | const i = blk: { |
| 1399 | var low: usize = 0; |
| 1400 | var high: usize = self.children.len; |
| 1401 | while (low < high) { |
| 1402 | const mid = low + (high - low) / 2; |
| 1403 | switch (Object.search(name, self.children[mid])) { |
| 1404 | .eq => break :blk mid, |
| 1405 | .gt => low = mid + 1, |
| 1406 | .lt => high = mid, |
| 1407 | } |
| 1408 | } |
| 1409 | for (self.children[low..], 0..) |item, i| { |
| 1410 | if (std.mem.startsWith(u8, item.name, name)) { |
| 1411 | if (item.name[name.len..].len == 0) { |
| 1412 | break :blk low + i; |
| 1413 | } |
| 1414 | if (std.math.order(item.name[name.len..][0], '/') == .gt) { |
| 1415 | return null; |
| 1416 | } |
| 1417 | continue; |
| 1418 | } |
| 1419 | break; |
| 1420 | } |
| 1421 | return null; |
| 1422 | }; |
| 1397 | 1423 | return self.children[i]; |
| 1398 | 1424 | } |
| 1399 | 1425 | |
| ... | ... | @@ -1424,10 +1450,10 @@ pub const Tree = struct { |
| 1424 | 1450 | id: AnyId, |
| 1425 | 1451 | name: [:0]const u8, |
| 1426 | 1452 | |
| 1427 | | fn search(a: struct { []const u8, Type }, b: Object) std.math.Order { |
| 1428 | | if (a[0].ptr != b.name.ptr) { |
| 1429 | | const n = @min(a[0].len, b.name.len); |
| 1430 | | for (a[0][0..n], b.name[0..n]) |lhs_elem, rhs_elem| { |
| 1453 | fn search(a: []const u8, b: Object) std.math.Order { |
| 1454 | if (a.ptr != b.name.ptr) { |
| 1455 | const n = @min(a.len, b.name.len); |
| 1456 | for (a[0..n], b.name[0..n]) |lhs_elem, rhs_elem| { |
| 1431 | 1457 | switch (std.math.order(lhs_elem, rhs_elem)) { |
| 1432 | 1458 | .eq => continue, |
| 1433 | 1459 | .lt => return .lt, |
| ... | ... | @@ -1435,9 +1461,9 @@ pub const Tree = struct { |
| 1435 | 1461 | } |
| 1436 | 1462 | } |
| 1437 | 1463 | } |
| 1438 | | return switch (std.math.order(a[0].len, b.name.len)) { |
| 1439 | | .lt => if (a[1] == .directory) std.math.order('/', b.name[a[0].len]) else .lt, |
| 1440 | | .gt => if (b.mode.type == .directory) std.math.order(a[0][b.name.len], '/') else .gt, |
| 1464 | return switch (std.math.order(a.len, b.name.len)) { |
| 1465 | .lt => .lt, |
| 1466 | .gt => if (b.mode.type == .directory) std.math.order(a[b.name.len], '/') else .gt, |
| 1441 | 1467 | .eq => .eq, |
| 1442 | 1468 | }; |
| 1443 | 1469 | } |