Skip to content

Commit 150ccb0

Browse files
committed
perf(codegen): reduce size of LineOffsetTable
1 parent b2da22b commit 150ccb0

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

crates/oxc_codegen/src/sourcemap_builder.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const PS_THIRD: u8 = 0xA9;
1616
/// Code is adapted from [esbuild](https://github.com/evanw/esbuild/blob/cc74e6042a9f573bf58e1e3f165ebda70af4ad3b/internal/js_printer/js_printer.go#L4806-L4808)
1717
#[derive(Debug)]
1818
pub struct LineOffsetTable {
19-
columns: Option<Vec<u32>>,
19+
columns: Option<Box<[u32]>>,
2020
byte_offset_to_first: u32,
2121
byte_offset_to_start_of_line: u32,
2222
}
@@ -212,8 +212,7 @@ impl SourcemapBuilder {
212212
// Create `columns` Vec, and set `byte_offset_to_first`.
213213
let table = tables.iter_mut().last().unwrap();
214214
table.byte_offset_to_first = byte_offset_from_line_start;
215-
table.columns = Some(vec![]);
216-
let columns = table.columns.as_mut().unwrap();
215+
let mut columns = vec![];
217216

218217
// Loop through rest of line char-by-char.
219218
// `chunk_byte_offset` in this loop is byte offset from start of this 1st
@@ -256,13 +255,21 @@ impl SourcemapBuilder {
256255
// Line break found.
257256
// `chunk_byte_offset` is now the offset of *end* of the line break.
258257
line_byte_offset += chunk_byte_offset;
258+
259+
// Record array of columns
260+
table.columns = Some(columns.into_boxed_slice());
261+
259262
// Revert back to outer loop for next line
260263
continue 'lines;
261264
}
262265

263266
// EOF.
264267
// One last column entry for EOF position.
265268
columns.push(column);
269+
270+
// Record array of columns
271+
table.columns = Some(columns.into_boxed_slice());
272+
266273
break 'lines;
267274
}
268275
};

0 commit comments

Comments
 (0)