From d124d7bdd69f3c233aa1c3f7437d9b1fa95a4bd6 Mon Sep 17 00:00:00 2001 From: gustavo-shigueo Date: Thu, 25 Jul 2024 11:19:06 -0300 Subject: [PATCH] Allocate less space for buffer by having the note from the original file be reused --- ts-rs/src/export.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ts-rs/src/export.rs b/ts-rs/src/export.rs index 03374d81..bf2bf660 100644 --- a/ts-rs/src/export.rs +++ b/ts-rs/src/export.rs @@ -165,7 +165,7 @@ fn export_and_merge(path: PathBuf, type_name: String, generated_type: String) -> let buffer = merge(original_contents, generated_type); - file.seek(SeekFrom::Start(0))?; + file.seek(SeekFrom::Start(NOTE.len() as u64))?; file.write_all(buffer.as_bytes())?; file.sync_all()?; @@ -195,12 +195,10 @@ fn merge(original_contents: String, new_contents: String) -> String { .collect::>(); let import_len = imports.iter().map(|&x| x.len()).sum::() + imports.len(); - let capacity = NOTE.len() + import_len + original_decls.len() + new_decl.len() + 2; + let capacity = import_len + original_decls.len() + new_decl.len() + 2; let mut buffer = String::with_capacity(capacity); - buffer.push_str(NOTE); - for import in imports { buffer.push_str(import); buffer.push('\n')