aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/js_printer.zig28
1 files changed, 17 insertions, 11 deletions
diff --git a/src/js_printer.zig b/src/js_printer.zig
index f8f56d91a..54b1a2991 100644
--- a/src/js_printer.zig
+++ b/src/js_printer.zig
@@ -4349,6 +4349,15 @@ pub const BufferWriter = struct {
ctx.approximate_newline_count = 0;
}
+ pub fn writtenWithoutTrailingZero(ctx: *const BufferWriter) []u8 {
+ var written = ctx.written;
+ while (written.len > 0 and written[written.len - 1] == 0) {
+ written = written[0 .. written.len - 1];
+ }
+
+ return written;
+ }
+
pub fn done(
ctx: *BufferWriter,
) anyerror!void {
@@ -4604,19 +4613,16 @@ pub fn printCommonJSThreaded(
if (comptime Environment.isMac or Environment.isLinux) {
// Don't bother preallocate the file if it's less than 1 KB. Preallocating is potentially two syscalls
if (printer.writer.written > 1024) {
- if (comptime Environment.isMac) {
- try C.preallocate_file(
- getter.handle,
- @intCast(std.os.off_t, 0),
- @intCast(std.os.off_t, printer.writer.written),
- );
- }
-
- if (comptime Environment.isLinux) {
- _ = std.os.system.fallocate(getter.handle, 0, @intCast(i64, result.off), printer.writer.written);
- }
+ // on mac, it's relative to current position in file handle
+ // on linux, it's absolute
+ try C.preallocate_file(
+ getter.handle,
+ @intCast(std.os.off_t, if (comptime Environment.isMac) 0 else result.off),
+ @intCast(std.os.off_t, printer.writer.written),
+ );
}
}
+
try printer.writer.done();
@fence(.SeqCst);
result.end_off = @truncate(u32, try getPos(getter));