@@ -248,7 +248,7 @@ const Contents = struct {
248
248
};
249
249
250
250
const HashToContents = std .StringHashMap (Contents );
251
- const TargetToHash = std .HashMap (DestTarget , []const u8 , DestTarget .hash , DestTarget .eql );
251
+ const TargetToHash = std .HashMap (DestTarget , []const u8 , DestTarget .hash , DestTarget .eql , true );
252
252
const PathTable = std .StringHashMap (* TargetToHash );
253
253
254
254
const LibCVendor = enum {
@@ -339,7 +339,7 @@ pub fn main() !void {
339
339
try dir_stack .append (target_include_dir );
340
340
341
341
while (dir_stack .popOrNull ()) | full_dir_name | {
342
- var dir = std .fs .cwd ().openDirList (full_dir_name ) catch | err | switch (err ) {
342
+ var dir = std .fs .cwd ().openDir (full_dir_name , .{ . iterate = true } ) catch | err | switch (err ) {
343
343
error .FileNotFound = > continue :search ,
344
344
error .AccessDenied = > continue :search ,
345
345
else = > return err ,
@@ -354,7 +354,8 @@ pub fn main() !void {
354
354
.Directory = > try dir_stack .append (full_path ),
355
355
.File = > {
356
356
const rel_path = try std .fs .path .relative (allocator , target_include_dir , full_path );
357
- const raw_bytes = try std .io .readFileAlloc (allocator , full_path );
357
+ const max_size = 2 * 1024 * 1024 * 1024 ;
358
+ const raw_bytes = try std .fs .cwd ().readFileAlloc (allocator , full_path , max_size );
358
359
const trimmed = std .mem .trim (u8 , raw_bytes , " \r \n \t " );
359
360
total_bytes += raw_bytes .len ;
360
361
const hash = try allocator .alloc (u8 , 32 );
@@ -365,28 +366,28 @@ pub fn main() !void {
365
366
const gop = try hash_to_contents .getOrPut (hash );
366
367
if (gop .found_existing ) {
367
368
max_bytes_saved += raw_bytes .len ;
368
- gop .kv .value .hit_count += 1 ;
369
+ gop .entry .value .hit_count += 1 ;
369
370
std .debug .warn ("duplicate: {} {} ({Bi:2})\n " , .{
370
371
libc_target .name ,
371
372
rel_path ,
372
373
raw_bytes .len ,
373
374
});
374
375
} else {
375
- gop .kv .value = Contents {
376
+ gop .entry .value = Contents {
376
377
.bytes = trimmed ,
377
378
.hit_count = 1 ,
378
379
.hash = hash ,
379
380
.is_generic = false ,
380
381
};
381
382
}
382
383
const path_gop = try path_table .getOrPut (rel_path );
383
- const target_to_hash = if (path_gop .found_existing ) path_gop .kv .value else blk : {
384
+ const target_to_hash = if (path_gop .found_existing ) path_gop .entry .value else blk : {
384
385
const ptr = try allocator .create (TargetToHash );
385
386
ptr .* = TargetToHash .init (allocator );
386
- path_gop .kv .value = ptr ;
387
+ path_gop .entry .value = ptr ;
387
388
break :blk ptr ;
388
389
};
389
- assert (( try target_to_hash .put (dest_target , hash )) == null );
390
+ try target_to_hash .putNoClobber (dest_target , hash );
390
391
},
391
392
else = > std .debug .warn ("warning: weird file: {}\n " , .{full_path }),
392
393
}
@@ -410,7 +411,7 @@ pub fn main() !void {
410
411
{
411
412
var hash_it = path_kv .value .iterator ();
412
413
while (hash_it .next ()) | hash_kv | {
413
- const contents = & hash_to_contents .get (hash_kv .value ).? . value ;
414
+ const contents = & hash_to_contents .get (hash_kv .value ).? ;
414
415
try contents_list .append (contents );
415
416
}
416
417
}
@@ -432,7 +433,7 @@ pub fn main() !void {
432
433
}
433
434
var hash_it = path_kv .value .iterator ();
434
435
while (hash_it .next ()) | hash_kv | {
435
- const contents = & hash_to_contents .get (hash_kv .value ).? . value ;
436
+ const contents = & hash_to_contents .get (hash_kv .value ).? ;
436
437
if (contents .is_generic ) continue ;
437
438
438
439
const dest_target = hash_kv .key ;
0 commit comments