Skip to content

Commit

Permalink
Allocate less space for buffer by having the note from the original f…
Browse files Browse the repository at this point in the history
…ile be reused
  • Loading branch information
gustavo-shigueo committed Jul 25, 2024
1 parent ad1b46e commit d124d7b
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions ts-rs/src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?;
Expand Down Expand Up @@ -195,12 +195,10 @@ fn merge(original_contents: String, new_contents: String) -> String {
.collect::<BTreeSet<_>>();

let import_len = imports.iter().map(|&x| x.len()).sum::<usize>() + 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')
Expand Down

0 comments on commit d124d7b

Please sign in to comment.