Skip to content

Commit

Permalink
Only clone Arc for source text
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Aug 5, 2024
1 parent 03f4745 commit 6378279
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions crates/oxc_sourcemap/src/concat_sourcemap_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,20 @@ impl ConcatSourceMapBuilder {
}

// Extend `sources` and `source_contents`.
self.sources.extend(sourcemap.sources.iter().map(Arc::clone));
self.sources.extend(sourcemap.get_sources().map(Into::into));

if let Some(source_contents) = &sourcemap.source_contents {
// Clone `Arc` instead of generating a new `Arc` and copying string data because
// source texts are generally long strings. Cost of copying a large string is higher
// than cloning an `Arc`.
self.source_contents.extend(source_contents.iter().map(Arc::clone));
} else {
self.source_contents.extend((0..sourcemap.sources.len()).map(|_| Arc::default()));
}

// Extend `names`.
self.names.reserve(sourcemap.names.len());
self.names.extend(sourcemap.names.iter().map(Arc::clone));
self.names.extend(sourcemap.get_names().map(Into::into));

// Extend `tokens`.
self.tokens.reserve(sourcemap.tokens.len());
Expand Down

0 comments on commit 6378279

Please sign in to comment.