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
58 changes: 29 additions & 29 deletions lib/source-map-consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ BasicSourceMapConsumer.prototype._parseMappings =
var index = 0;
var temp = {};
var generatedMappings = [];
var mapping, value, charCode;
var value, charCode;
// Reuse segment array to avoid allocations per mapping
var segment = [0, 0, 0, 0, 0];
var segmentLength = 0;
Expand All @@ -653,15 +653,6 @@ BasicSourceMapConsumer.prototype._parseMappings =
index++;
}
else {
mapping = {
generatedLine: generatedLine,
generatedColumn: 0,
source: null,
originalLine: null,
originalColumn: null,
name: null
};

// Decode VLQ values until we hit a separator
segmentLength = 0;
while (index < length) {
Expand Down Expand Up @@ -690,33 +681,42 @@ BasicSourceMapConsumer.prototype._parseMappings =
throw new Error('Found a source and line, but no column');
}

// Generated column.
mapping.generatedColumn = previousGeneratedColumn + segment[0];
previousGeneratedColumn = mapping.generatedColumn;

// Compute every mapping field into a local before allocating the
// literal. Building the object in one shot lets V8 settle on a
// single hidden class per mapping shape; the previous code wrote
// nulls into source/originalLine/originalColumn/name and then
// overwrote them with numbers, which trips per-field shape
// transitions and slows downstream reads (eachMapping iteration
// was the visible loser).
var genCol = previousGeneratedColumn + segment[0];
previousGeneratedColumn = genCol;

var src = null, origLine = null, origCol = null, nameIdx = null;
if (segmentLength > 1) {
// Original source.
mapping.source = previousSource + segment[1];
previousSource += segment[1];
src = previousSource + segment[1];
previousSource = src;

// Original line.
mapping.originalLine = previousOriginalLine + segment[2];
previousOriginalLine = mapping.originalLine;
// Lines are stored 0-based
mapping.originalLine += 1;
var origLine0 = previousOriginalLine + segment[2];
previousOriginalLine = origLine0;
origLine = origLine0 + 1; // stored 1-based

// Original column.
mapping.originalColumn = previousOriginalColumn + segment[3];
previousOriginalColumn = mapping.originalColumn;
origCol = previousOriginalColumn + segment[3];
previousOriginalColumn = origCol;

if (segmentLength > 4) {
// Original name.
mapping.name = previousName + segment[4];
previousName += segment[4];
nameIdx = previousName + segment[4];
previousName = nameIdx;
}
}

generatedMappings.push(mapping);
generatedMappings.push({
generatedLine: generatedLine,
generatedColumn: genCol,
source: src,
originalLine: origLine,
originalColumn: origCol,
name: nameIdx
});
}
}

Expand Down
Loading