Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions crates/oxc_codegen/src/sourcemap_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ impl<'a> SourcemapBuilder<'a> {
let mut column_offsets = IndexVec::new();

// Used as a buffer to reduce memory reallocations
let mut columns = vec![];
// Pre-allocate with reasonable capacity to avoid frequent reallocations
let mut columns = Vec::with_capacity(256);

// Process content line-by-line.
// For each line, start by assuming line will be entirely ASCII, and read byte-by-byte.
Expand Down Expand Up @@ -389,11 +390,13 @@ impl<'a> SourcemapBuilder<'a> {
line_byte_offset += chunk_byte_offset;

// Record column offsets
// Use mem::take to avoid clone - moves columns out and replaces with empty Vec
column_offsets.push(ColumnOffsets {
byte_offset_to_first: byte_offset_from_line_start,
columns: columns.clone().into_boxed_slice(),
columns: std::mem::take(&mut columns).into_boxed_slice(),
});
columns.clear();
// Reserve capacity for next line to avoid reallocation
columns.reserve(256);

// Revert back to outer loop for next line
continue 'lines;
Expand Down
Loading