| ... | @@ -536,24 +536,24 @@ test "Dir.Iterator" { | ... | @@ -536,24 +536,24 @@ test "Dir.Iterator" { |
| 536 | | 536 | |
| 537 | try tmp_dir.dir.createDir(io, "some_dir", .default_dir); | 537 | try tmp_dir.dir.createDir(io, "some_dir", .default_dir); |
| 538 | | 538 | |
| 539 | var arena = ArenaAllocator.init(testing.allocator); | 539 | var arena_instance = ArenaAllocator.init(testing.allocator); |
| 540 | defer arena.deinit(); | 540 | defer arena_instance.deinit(); |
| 541 | const allocator = arena.allocator(); | 541 | const arena = arena_instance.allocator(); |
| 542 | | 542 | |
| 543 | var entries = std.array_list.Managed(Dir.Entry).init(allocator); | 543 | var entries: std.ArrayList(Dir.Entry) = .empty; |
| 544 | | 544 | |
| 545 | // Create iterator. | 545 | // Create iterator. |
| 546 | var iter = tmp_dir.dir.iterate(); | 546 | var iter = tmp_dir.dir.iterate(); |
| 547 | while (try iter.next(io)) |entry| { | 547 | while (try iter.next(io)) |entry| { |
| 548 | // We cannot just store `entry` as on Windows, we're re-using the name buffer | 548 | // We cannot just store `entry` as on Windows, we're re-using the name buffer |
| 549 | // which means we'll actually share the `name` pointer between entries! | 549 | // which means we'll actually share the `name` pointer between entries! |
| 550 | const name = try allocator.dupe(u8, entry.name); | 550 | const name = try arena.dupe(u8, entry.name); |
| 551 | try entries.append(Dir.Entry{ .name = name, .kind = entry.kind, .inode = 0 }); | 551 | try entries.append(arena, Dir.Entry{ .name = name, .kind = entry.kind, .inode = 0 }); |
| 552 | } | 552 | } |
| 553 | | 553 | |
| 554 | try expectEqual(@as(usize, 2), entries.items.len); // note that the Iterator skips '.' and '..' | 554 | try expectEqual(@as(usize, 2), entries.items.len); // note that the Iterator skips '.' and '..' |
| 555 | try expect(contains(&entries, .{ .name = "some_file", .kind = .file, .inode = 0 })); | 555 | try expect(contains(entries.items, .{ .name = "some_file", .kind = .file, .inode = 0 })); |
| 556 | try expect(contains(&entries, .{ .name = "some_dir", .kind = .directory, .inode = 0 })); | 556 | try expect(contains(entries.items, .{ .name = "some_dir", .kind = .directory, .inode = 0 })); |
| 557 | } | 557 | } |
| 558 | | 558 | |
| 559 | test "Dir.Iterator many entries" { | 559 | test "Dir.Iterator many entries" { |
| ... | @@ -571,25 +571,25 @@ test "Dir.Iterator many entries" { | ... | @@ -571,25 +571,25 @@ test "Dir.Iterator many entries" { |
| 571 | file.close(io); | 571 | file.close(io); |
| 572 | } | 572 | } |
| 573 | | 573 | |
| 574 | var arena = ArenaAllocator.init(testing.allocator); | 574 | var arena_instance = ArenaAllocator.init(testing.allocator); |
| 575 | defer arena.deinit(); | 575 | defer arena_instance.deinit(); |
| 576 | const allocator = arena.allocator(); | 576 | const arena = arena_instance.allocator(); |
| 577 | | 577 | |
| 578 | var entries = std.array_list.Managed(Dir.Entry).init(allocator); | 578 | var entries: std.ArrayList(Dir.Entry) = .empty; |
| 579 | | 579 | |
| 580 | // Create iterator. | 580 | // Create iterator. |
| 581 | var iter = tmp_dir.dir.iterate(); | 581 | var iter = tmp_dir.dir.iterate(); |
| 582 | while (try iter.next(io)) |entry| { | 582 | while (try iter.next(io)) |entry| { |
| 583 | // We cannot just store `entry` as on Windows, we're re-using the name buffer | 583 | // We cannot just store `entry` as on Windows, we're re-using the name buffer |
| 584 | // which means we'll actually share the `name` pointer between entries! | 584 | // which means we'll actually share the `name` pointer between entries! |
| 585 | const name = try allocator.dupe(u8, entry.name); | 585 | const name = try arena.dupe(u8, entry.name); |
| 586 | try entries.append(.{ .name = name, .kind = entry.kind, .inode = 0 }); | 586 | try entries.append(arena, .{ .name = name, .kind = entry.kind, .inode = 0 }); |
| 587 | } | 587 | } |
| 588 | | 588 | |
| 589 | i = 0; | 589 | i = 0; |
| 590 | while (i < num) : (i += 1) { | 590 | while (i < num) : (i += 1) { |
| 591 | const name = try std.mem.print(&buf, "{}", .{i}); | 591 | const name = try std.mem.print(&buf, "{}", .{i}); |
| 592 | try expect(contains(&entries, .{ .name = name, .kind = .file, .inode = 0 })); | 592 | try expect(contains(entries.items, .{ .name = name, .kind = .file, .inode = 0 })); |
| 593 | } | 593 | } |
| 594 | } | 594 | } |
| 595 | | 595 | |
| ... | @@ -605,26 +605,26 @@ test "Dir.Iterator twice" { | ... | @@ -605,26 +605,26 @@ test "Dir.Iterator twice" { |
| 605 | | 605 | |
| 606 | try tmp_dir.dir.createDir(io, "some_dir", .default_dir); | 606 | try tmp_dir.dir.createDir(io, "some_dir", .default_dir); |
| 607 | | 607 | |
| 608 | var arena = ArenaAllocator.init(testing.allocator); | 608 | var arena_instance = ArenaAllocator.init(testing.allocator); |
| 609 | defer arena.deinit(); | 609 | defer arena_instance.deinit(); |
| 610 | const allocator = arena.allocator(); | 610 | const arena = arena_instance.allocator(); |
| 611 | | 611 | |
| 612 | var i: u8 = 0; | 612 | var i: u8 = 0; |
| 613 | while (i < 2) : (i += 1) { | 613 | while (i < 2) : (i += 1) { |
| 614 | var entries = std.array_list.Managed(Dir.Entry).init(allocator); | 614 | var entries: std.ArrayList(Dir.Entry) = .empty; |
| 615 | | 615 | |
| 616 | // Create iterator. | 616 | // Create iterator. |
| 617 | var iter = tmp_dir.dir.iterate(); | 617 | var iter = tmp_dir.dir.iterate(); |
| 618 | while (try iter.next(io)) |entry| { | 618 | while (try iter.next(io)) |entry| { |
| 619 | // We cannot just store `entry` as on Windows, we're re-using the name buffer | 619 | // We cannot just store `entry` as on Windows, we're re-using the name buffer |
| 620 | // which means we'll actually share the `name` pointer between entries! | 620 | // which means we'll actually share the `name` pointer between entries! |
| 621 | const name = try allocator.dupe(u8, entry.name); | 621 | const name = try arena.dupe(u8, entry.name); |
| 622 | try entries.append(Dir.Entry{ .name = name, .kind = entry.kind, .inode = 0 }); | 622 | try entries.append(arena, Dir.Entry{ .name = name, .kind = entry.kind, .inode = 0 }); |
| 623 | } | 623 | } |
| 624 | | 624 | |
| 625 | try expectEqual(@as(usize, 2), entries.items.len); // note that the Iterator skips '.' and '..' | 625 | try expectEqual(@as(usize, 2), entries.items.len); // note that the Iterator skips '.' and '..' |
| 626 | try expect(contains(&entries, .{ .name = "some_file", .kind = .file, .inode = 0 })); | 626 | try expect(contains(entries.items, .{ .name = "some_file", .kind = .file, .inode = 0 })); |
| 627 | try expect(contains(&entries, .{ .name = "some_dir", .kind = .directory, .inode = 0 })); | 627 | try expect(contains(entries.items, .{ .name = "some_dir", .kind = .directory, .inode = 0 })); |
| 628 | } | 628 | } |
| 629 | } | 629 | } |
| 630 | | 630 | |
| ... | @@ -640,27 +640,27 @@ test "Dir.Iterator reset" { | ... | @@ -640,27 +640,27 @@ test "Dir.Iterator reset" { |
| 640 | | 640 | |
| 641 | try tmp_dir.dir.createDir(io, "some_dir", .default_dir); | 641 | try tmp_dir.dir.createDir(io, "some_dir", .default_dir); |
| 642 | | 642 | |
| 643 | var arena = ArenaAllocator.init(testing.allocator); | 643 | var arena_instance = ArenaAllocator.init(testing.allocator); |
| 644 | defer arena.deinit(); | 644 | defer arena_instance.deinit(); |
| 645 | const allocator = arena.allocator(); | 645 | const arena = arena_instance.allocator(); |
| 646 | | 646 | |
| 647 | // Create iterator. | 647 | // Create iterator. |
| 648 | var iter = tmp_dir.dir.iterate(); | 648 | var iter = tmp_dir.dir.iterate(); |
| 649 | | 649 | |
| 650 | var i: u8 = 0; | 650 | var i: u8 = 0; |
| 651 | while (i < 2) : (i += 1) { | 651 | while (i < 2) : (i += 1) { |
| 652 | var entries = std.array_list.Managed(Dir.Entry).init(allocator); | 652 | var entries: std.ArrayList(Dir.Entry) = .empty; |
| 653 | | 653 | |
| 654 | while (try iter.next(io)) |entry| { | 654 | while (try iter.next(io)) |entry| { |
| 655 | // We cannot just store `entry` as on Windows, we're re-using the name buffer | 655 | // We cannot just store `entry` as on Windows, we're re-using the name buffer |
| 656 | // which means we'll actually share the `name` pointer between entries! | 656 | // which means we'll actually share the `name` pointer between entries! |
| 657 | const name = try allocator.dupe(u8, entry.name); | 657 | const name = try arena.dupe(u8, entry.name); |
| 658 | try entries.append(.{ .name = name, .kind = entry.kind, .inode = 0 }); | 658 | try entries.append(arena, .{ .name = name, .kind = entry.kind, .inode = 0 }); |
| 659 | } | 659 | } |
| 660 | | 660 | |
| 661 | try expectEqual(@as(usize, 2), entries.items.len); // note that the Iterator skips '.' and '..' | 661 | try expectEqual(@as(usize, 2), entries.items.len); // note that the Iterator skips '.' and '..' |
| 662 | try expect(contains(&entries, .{ .name = "some_file", .kind = .file, .inode = 0 })); | 662 | try expect(contains(entries.items, .{ .name = "some_file", .kind = .file, .inode = 0 })); |
| 663 | try expect(contains(&entries, .{ .name = "some_dir", .kind = .directory, .inode = 0 })); | 663 | try expect(contains(entries.items, .{ .name = "some_dir", .kind = .directory, .inode = 0 })); |
| 664 | | 664 | |
| 665 | iter.reader.reset(); | 665 | iter.reader.reset(); |
| 666 | } | 666 | } |
| ... | @@ -696,11 +696,10 @@ fn entryEql(lhs: Dir.Entry, rhs: Dir.Entry) bool { | ... | @@ -696,11 +696,10 @@ fn entryEql(lhs: Dir.Entry, rhs: Dir.Entry) bool { |
| 696 | return mem.eql(u8, lhs.name, rhs.name) and lhs.kind == rhs.kind; | 696 | return mem.eql(u8, lhs.name, rhs.name) and lhs.kind == rhs.kind; |
| 697 | } | 697 | } |
| 698 | | 698 | |
| 699 | fn contains(entries: *const std.array_list.Managed(Dir.Entry), el: Dir.Entry) bool { | 699 | fn contains(entries: []const Dir.Entry, el: Dir.Entry) bool { |
| 700 | for (entries.items) |entry| { | 700 | return for (entries) |entry| { |
| 701 | if (entryEql(entry, el)) return true; | 701 | if (entryEql(entry, el)) break true; |
| 702 | } | 702 | } else false; |
| 703 | return false; | | |
| 704 | } | 703 | } |
| 705 | | 704 | |
| 706 | test "Dir.realPath smoke test" { | 705 | test "Dir.realPath smoke test" { |