Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(sourcemap): keep local copy of previous token in VLQ encode #4596

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
6 changes: 5 additions & 1 deletion crates/oxc_sourcemap/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ fn serialize_mappings(tokens: &[Token], token_chunk: &TokenChunk) -> String {

let mut rv = String::with_capacity(capacity);

let mut prev_token = if start == 0 { None } else { Some(&tokens[start as usize - 1]) };

for (idx, token) in tokens[start as usize..end as usize].iter().enumerate() {
// Max length of a single VLQ encoding is 7 bytes. Max number of calls to `encode_vlq_diff` is 5.
// Also need 1 byte for each line number difference, or 1 byte if no line num difference.
Expand All @@ -149,7 +151,7 @@ fn serialize_mappings(tokens: &[Token], token_chunk: &TokenChunk) -> String {
prev_dst_col = 0;
prev_dst_line += num_line_breaks;
} else if index > 0 {
if Some(token) == tokens.get(index - 1) {
if prev_token == Some(token) {
continue;
}
rv.reserve(MAX_TOTAL_VLQ_BYTES + 1);
Expand All @@ -176,6 +178,8 @@ fn serialize_mappings(tokens: &[Token], token_chunk: &TokenChunk) -> String {
}
}
}

prev_token = Some(token);
}

rv
Expand Down