Skip to content
Open
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
33 changes: 28 additions & 5 deletions lib/source-map-consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,21 @@ function sortGenerated(array, start) {
quickSort(array, compareGenerated, start);
}
}
// Lookup table for single-byte VLQ decode (no continuation bit)
// Maps base64 char code -> decoded signed value, or undefined if multi-byte
var vlqTable = [];
(function() {
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
for (var i = 0; i < 128; i++) vlqTable[i] = undefined;
// Only first 32 base64 values (A-f) are single-byte VLQ (no continuation bit)
for (var i = 0; i < 32; i++) {
var charCode = chars.charCodeAt(i);
// Single-byte VLQ: bit 0 is sign, bits 1-4 are value
var value = i >> 1;
vlqTable[charCode] = (i & 1) ? -value : value;
}
})();

BasicSourceMapConsumer.prototype._parseMappings =
function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
var generatedLine = 1;
Expand All @@ -516,7 +531,7 @@ BasicSourceMapConsumer.prototype._parseMappings =
var temp = {};
var originalMappings = [];
var generatedMappings = [];
var mapping, str, segment, end, value;
var mapping, str, segment, end, value, charCode;

let subarrayStart = 0;
while (index < length) {
Expand Down Expand Up @@ -544,10 +559,18 @@ BasicSourceMapConsumer.prototype._parseMappings =

segment = [];
while (index < end) {
base64VLQ.decode(aStr, index, temp);
value = temp.value;
index = temp.rest;
segment.push(value);
// Fast path for single-byte VLQ (most common case)
charCode = aStr.charCodeAt(index);
value = vlqTable[charCode];
if (value !== undefined) {
index++;
segment.push(value);
} else {
base64VLQ.decode(aStr, index, temp);
value = temp.value;
index = temp.rest;
segment.push(value);
}
}

if (segment.length === 2) {
Expand Down