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
37 changes: 31 additions & 6 deletions lib/source-map-consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
var util = require('./util');
var binarySearch = require('./binary-search');
var ArraySet = require('./array-set').ArraySet;
var base64VLQ = require('./base64-vlq');
// `base64DecodeTable` maps a base64 character code → its 6-bit decoded value,
// with `255` as the invalid-char sentinel. Imported directly so the inlined
// multi-byte VLQ slow path in `_parseMappings` can index it without going
// through a wrapper function — same direct-table pattern PR #67 applied to
// `_names._array`.
var base64DecodeTable = require('./base64').charToIntMap;

function SourceMapConsumer(aSourceMap, aSourceMapURL) {
var sourceMap = aSourceMap;
Expand Down Expand Up @@ -697,7 +702,6 @@ BasicSourceMapConsumer.prototype._parseMappings =
var previousName = 0;
var length = aStr.length;
var index = 0;
var temp = {};
var value, charCode;
// Reuse segment array to avoid allocations per mapping
var segment = [0, 0, 0, 0, 0];
Expand Down Expand Up @@ -738,10 +742,31 @@ BasicSourceMapConsumer.prototype._parseMappings =
index++;
segment[segmentLength++] = value;
} else {
base64VLQ.decode(aStr, index, temp);
value = temp.value;
index = temp.rest;
segment[segmentLength++] = value;
// Multi-byte VLQ decode — inlined. Indirect-dispatched
// base64VLQ.decode + the temp output object's `.value`/`.rest`
// round trip is more cost than the body itself for typical
// small deltas. Bit layout: bit 0 = sign, bits 1-4 = value
// (chunked 5-bit groups across continuation digits), bit 5 =
// continuation. `base64DecodeTable[c] === 255` marks an
// invalid base64 char.
var vlqResult = 0;
var vlqShift = 0;
var vlqDigit;
do {
if (index >= length) {
throw new Error('Expected more digits in base 64 VLQ value.');
}
var vlqC = aStr.charCodeAt(index++);
vlqDigit = vlqC < 128 ? base64DecodeTable[vlqC] : 255;
if (vlqDigit === 255) {
throw new Error('Invalid base64 digit: ' + aStr.charAt(index - 1));
}
vlqResult = vlqResult + ((vlqDigit & 31) << vlqShift);
vlqShift += 5;
} while ((vlqDigit & 32) !== 0);
segment[segmentLength++] = (vlqResult & 1) === 1
? -(vlqResult >> 1)
: (vlqResult >> 1);
}
}

Expand Down
Loading