authorgravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2022-05-30 16:48:34+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-19 19:10:12-07:00
log51647c305eea1c38da47e3c20b39418ce3a7689f
tree95c717756aa1fa8ad5fd6cc128aae4237f2e2f40
parentf07534069deaa500df075ca6424f4bce29dcd7f8

autodoc: add buffering to the json writer


1 files changed, 23 insertions(+), 16 deletions(-)

src/Autodoc.zig+23-16
...@@ -219,22 +219,29 @@ pub fn generateZirData(self: *Autodoc) !void {...@@ -219,22 +219,29 @@ pub fn generateZirData(self: *Autodoc) !void {
219 (d.handle.openDir(self.doc_location.basename, .{}) catch unreachable)219 (d.handle.openDir(self.doc_location.basename, .{}) catch unreachable)
220 else220 else
221 (self.module.zig_cache_artifact_directory.handle.openDir(self.doc_location.basename, .{}) catch unreachable);221 (self.module.zig_cache_artifact_directory.handle.openDir(self.doc_location.basename, .{}) catch unreachable);
222 const data_js_f = output_dir.createFile("data.js", .{}) catch unreachable;222 {
223 defer data_js_f.close();223 const data_js_f = output_dir.createFile("data.js", .{}) catch unreachable;
224 const out = data_js_f.writer();224 defer data_js_f.close();
225 out.print(225 var buffer = std.io.bufferedWriter(data_js_f.writer());
226 \\ /** @type {{DocData}} */226
227 \\ var zigAnalysis=227 const out = buffer.writer();
228 , .{}) catch unreachable;228 out.print(
229 std.json.stringify(229 \\ /** @type {{DocData}} */
230 data,230 \\ var zigAnalysis=
231 .{231 , .{}) catch unreachable;
232 .whitespace = .{},232 std.json.stringify(
233 .emit_null_optional_fields = false,233 data,
234 },234 .{
235 out,235 .whitespace = .{},
236 ) catch unreachable;236 .emit_null_optional_fields = false,
237 out.print(";", .{}) catch unreachable;237 },
238 out,
239 ) catch unreachable;
240 out.print(";", .{}) catch unreachable;
241
242 // last thing (that can fail) that we do is flush
243 buffer.flush() catch unreachable;
244 }
238 // copy main.js, index.html245 // copy main.js, index.html
239 const docs = try self.module.comp.zig_lib_directory.join(self.arena, &.{ "docs", std.fs.path.sep_str });246 const docs = try self.module.comp.zig_lib_directory.join(self.arena, &.{ "docs", std.fs.path.sep_str });
240 var docs_dir = std.fs.openDirAbsolute(docs, .{}) catch unreachable;247 var docs_dir = std.fs.openDirAbsolute(docs, .{}) catch unreachable;