chore: optimize build script
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing

This commit is contained in:
LordMZTE 2022-07-02 17:34:01 +02:00
parent 59b3a6ec67
commit d6e7095097
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6

View file

@ -220,19 +220,25 @@ fn installMmcPackJson(archive: *c.archive, entry: *c.archive_entry) !void {
.formatVersion = 1,
};
const json = try std.json.stringifyAlloc(
std.heap.c_allocator,
// We run the serializer twice, because we need to know the size ahead of time for zip.
// This is faster than allocating the json on the heap.
var counter = std.io.countingWriter(std.io.null_writer);
try std.json.stringify(
data,
.{ .emit_null_optional_fields = false },
counter.writer(),
);
defer std.heap.c_allocator.free(json);
entrySetFile(entry);
c.archive_entry_set_size(entry, @intCast(i64, json.len));
c.archive_entry_set_size(entry, @intCast(i64, counter.bytes_written));
c.archive_entry_set_pathname(entry, "mmc-pack.json");
try handleArchiveErr(c.archive_write_header(archive, entry), archive);
try (ArchiveWriter{ .context = archive }).writeAll(json);
try std.json.stringify(
data,
.{ .emit_null_optional_fields = false },
ArchiveWriter{ .context = archive },
);
}
fn readMods(list: *std.ArrayList([]u8), alloc: std.mem.Allocator) !void {