diff --git a/lib/source-map-consumer.js b/lib/source-map-consumer.js index b8d962ac..963e4240 100644 --- a/lib/source-map-consumer.js +++ b/lib/source-map-consumer.js @@ -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 @@ -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] }); } };