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
18 changes: 13 additions & 5 deletions lib/source-map-consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,14 @@ SourceMapConsumer.prototype.eachMapping =
throw new Error("Unknown order of iteration.");
}

var boundCallback = aCallback.bind(context);
var names = this._names;
// Skip the `Function.prototype.bind` allocation when no context was
// supplied — `aCallback || null` defaults to a null context, which is
// the same as calling the function unbound.
var cb = context !== null ? aCallback.bind(context) : aCallback;
// Direct reads of the underlying `_array` slot match the slab-direct
// pattern in `_serializeMappings` / `fromSourceMap`. Skips the `at()`
// bounds-check + function call per named mapping.
var nameArray = this._names._array;
// `_absoluteSources` is precomputed in both consumer constructors as
// `computeSourceURL(sourceRoot, _sources.at(i), sourceMapURL)`, so a
// direct index skips the per-call URL parse + resolve. Same memoization
Expand All @@ -183,13 +189,15 @@ SourceMapConsumer.prototype.eachMapping =

for (var i = 0, n = mappings.length; i < n; i++) {
var mapping = mappings[i];
boundCallback({
source: mapping.source === null ? null : absoluteSources[mapping.source],
var src = mapping.source;
var nm = mapping.name;
cb({
source: src === null ? null : absoluteSources[src],
generatedLine: mapping.generatedLine,
generatedColumn: mapping.generatedColumn,
originalLine: mapping.originalLine,
originalColumn: mapping.originalColumn,
name: mapping.name === null ? null : names.at(mapping.name)
name: nm === null ? null : nameArray[nm]
});
}
};
Expand Down
Loading