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
11 changes: 6 additions & 5 deletions crates/oxc_codegen/src/sourcemap_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ impl<'a> SourcemapBuilder<'a> {
let mut lines = vec![];
let mut column_offsets = IndexVec::new();

// Used as a buffer to reduce memory reallocations
let mut columns = vec![];

// Process content line-by-line.
// For each line, start by assuming line will be entirely ASCII, and read byte-by-byte.
// If line is all ASCII, UTF-8 columns and UTF-16 columns are the same,
Expand All @@ -325,7 +328,6 @@ impl<'a> SourcemapBuilder<'a> {
column_offsets_id: None,
});

let mut columns = vec![]; // Used as a buffer to reduce memory reallocations.
let remaining = &content.as_bytes()[line_byte_offset as usize..];
for (byte_offset_from_line_start, b) in remaining.iter().enumerate() {
#[expect(clippy::cast_possible_truncation)]
Expand All @@ -351,8 +353,6 @@ impl<'a> SourcemapBuilder<'a> {
line.column_offsets_id =
Some(ColumnOffsetsId::from_usize(column_offsets.len()));

columns.clear();

// Loop through rest of line char-by-char.
// `chunk_byte_offset` in this loop is byte offset from start of this 1st
// Unicode char.
Expand Down Expand Up @@ -396,8 +396,9 @@ impl<'a> SourcemapBuilder<'a> {
// Record column offsets
column_offsets.push(ColumnOffsets {
byte_offset_to_first: byte_offset_from_line_start,
columns: columns.into_iter().collect(),
columns: columns.clone().into_boxed_slice(),
});
columns.clear();

// Revert back to outer loop for next line
continue 'lines;
Expand All @@ -410,7 +411,7 @@ impl<'a> SourcemapBuilder<'a> {
// Record column offsets
column_offsets.push(ColumnOffsets {
byte_offset_to_first: byte_offset_from_line_start,
columns: columns.into_iter().collect(),
columns: columns.into_boxed_slice(),
});

break 'lines;
Expand Down
Loading