@@ -200,11 +200,12 @@ test "writeBlock/readBlock/readFirstItemFromBlock" {
200
200
var segment = MemorySegment .init (std .testing .allocator , .{});
201
201
defer segment .deinit (.delete );
202
202
203
- try segment .items .append (.{ .hash = 1 , .id = 1 });
204
- try segment .items .append (.{ .hash = 2 , .id = 1 });
205
- try segment .items .append (.{ .hash = 3 , .id = 1 });
206
- try segment .items .append (.{ .hash = 3 , .id = 2 });
207
- try segment .items .append (.{ .hash = 4 , .id = 1 });
203
+ try segment .items .ensureTotalCapacity (std .testing .allocator , 5 );
204
+ segment .items .appendAssumeCapacity (.{ .hash = 1 , .id = 1 });
205
+ segment .items .appendAssumeCapacity (.{ .hash = 2 , .id = 1 });
206
+ segment .items .appendAssumeCapacity (.{ .hash = 3 , .id = 1 });
207
+ segment .items .appendAssumeCapacity (.{ .hash = 3 , .id = 2 });
208
+ segment .items .appendAssumeCapacity (.{ .hash = 4 , .id = 1 });
208
209
209
210
const block_size = 1024 ;
210
211
var block_data : [block_size ]u8 = undefined ;
@@ -442,8 +443,8 @@ pub fn readSegmentFile(dir: fs.Dir, info: SegmentInfo, segment: *FileSegment) !v
442
443
443
444
const blocks_data_start = fixed_buffer_stream .pos ;
444
445
445
- const estimated_block_count = (raw_data .len - fixed_buffer_stream .pos ) / block_size ;
446
- try segment .index .ensureTotalCapacity (estimated_block_count );
446
+ const max_possible_block_count = (raw_data .len - fixed_buffer_stream .pos ) / block_size ;
447
+ try segment .index .ensureTotalCapacity (segment . allocator , max_possible_block_count );
447
448
448
449
var num_items : u32 = 0 ;
449
450
var num_blocks : u32 = 0 ;
@@ -457,7 +458,7 @@ pub fn readSegmentFile(dir: fs.Dir, info: SegmentInfo, segment: *FileSegment) !v
457
458
if (block_header .num_items == 0 ) {
458
459
break ;
459
460
}
460
- try segment .index .append (block_header .first_item .hash );
461
+ segment .index .appendAssumeCapacity (block_header .first_item .hash );
461
462
num_items += block_header .num_items ;
462
463
num_blocks += 1 ;
463
464
crc .update (block_data [0.. ]);
0 commit comments