Improve build speed

This improves the speed of clearing of the FAT image with using a bigger buffer
Zig master
This commit is contained in:
Edward Dean 2021-03-05 17:03:20 +00:00
parent 0d2325d73a
commit 64a91ff7e4
2 changed files with 27 additions and 4 deletions

View file

@ -555,6 +555,29 @@ pub const Fat32 = struct {
};
}
///
/// Clear the stream. This is the same as writeByteNTimes but with a bigger buffer (4096 bytes).
/// This improves performance a lot.
///
/// Arguments:
/// IN stream: anytype - The stream to clear.
/// IN size: usize - The size to clear from the beginning
///
/// Error: @TypeOf(stream).WriteError
/// @TypeOf(stream).WriteError - Error writing to the stream.
///
fn clearStream(stream: anytype, size: usize) ErrorSet(@TypeOf(stream))!void {
comptime const buff_size = 4096;
comptime const bytes: [buff_size]u8 = [_]u8{0x00} ** buff_size;
var remaining: usize = size;
while (remaining > 0) {
const to_write = std.math.min(remaining, bytes.len);
try stream.writer().writeAll(bytes[0..to_write]);
remaining -= to_write;
}
}
///
/// Make a FAT32 image. This will either use the default options or modified defaults from the
/// user. The file will be saved to the path specified. If quick format is on, then the entire
@ -583,10 +606,10 @@ pub const Fat32 = struct {
try stream.seekableStream().seekTo(0);
if (quick_format) {
// Zero just the reserved and FAT sectors
try stream.writer().writeByteNTimes(0x00, (fat32_header.reserved_sectors + (fat32_header.sectors_per_fat * 2)) * fat32_header.bytes_per_sector);
try clearStream(stream, (fat32_header.reserved_sectors + (fat32_header.sectors_per_fat * 2)) * fat32_header.bytes_per_sector);
} else {
const image_size = std.mem.alignBackward(options.image_size, fat32_header.bytes_per_sector);
try stream.writer().writeByteNTimes(0x00, image_size);
try clearStream(stream, image_size);
}
// Write the boot sector with the bootstrap code and header and the backup boot sector.

View file

@ -206,7 +206,7 @@ pub const RuntimeStep = struct {
try self.os_proc.spawn();
// Start up the read thread
var thread = try Thread.spawn(self, read_logs);
var thread = try Thread.spawn(read_logs, self);
// Call the testing function
const res = self.test_func(self);