Skip to content

Commit 1b1d8f2

Browse files
committed
Backport mozilla#308 onto 0.6.1
1 parent ac518d2 commit 1b1d8f2

12 files changed

+3866
-40
lines changed

dist/source-map.debug.js

Lines changed: 58 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/source-map.js

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,43 @@ return /******/ (function(modules) { // webpackBootstrap
786786
}
787787
exports.urlGenerate = urlGenerate;
788788

789+
var MAX_CACHED_INPUTS = 32;
790+
791+
/**
792+
* Takes some function `f(input) -> result` and returns a memoized version of
793+
* `f`.
794+
*
795+
* We keep at most `MAX_CACHED_INPUTS` memoized results of `f` alive. The
796+
* memoization is a dumb-simple, linear least-recently-used cache.
797+
*/
798+
function lruMemoize(f) {
799+
var cache = [];
800+
801+
return function(input) {
802+
for (var i = 0; i < cache.length; i++) {
803+
if (cache[i].input === input) {
804+
var temp = cache[0];
805+
cache[0] = cache[i];
806+
cache[i] = temp;
807+
return cache[0].result;
808+
}
809+
}
810+
811+
var result = f(input);
812+
813+
cache.unshift({
814+
input,
815+
result,
816+
});
817+
818+
if (cache.length > MAX_CACHED_INPUTS) {
819+
cache.pop();
820+
}
821+
822+
return result;
823+
};
824+
}
825+
789826
/**
790827
* Normalizes a path, or the path portion of a URL:
791828
*
@@ -797,7 +834,7 @@ return /******/ (function(modules) { // webpackBootstrap
797834
*
798835
* @param aPath The path or url to normalize.
799836
*/
800-
function normalize(aPath) {
837+
var normalize = lruMemoize(function normalize(aPath) {
801838
var path = aPath;
802839
var url = urlParse(aPath);
803840
if (url) {
@@ -807,8 +844,25 @@ return /******/ (function(modules) { // webpackBootstrap
807844
path = url.path;
808845
}
809846
var isAbsolute = exports.isAbsolute(path);
847+
// Split the path into parts between `/` characters. This is much faster than
848+
// using `.split(/\/+/g)`.
849+
var parts = [];
850+
var start = 0;
851+
var i = 0;
852+
while (true) {
853+
start = i;
854+
i = path.indexOf("/", start);
855+
if (i === -1) {
856+
parts.push(path.slice(start));
857+
break;
858+
} else {
859+
parts.push(path.slice(start, i));
860+
while (i < path.length && path[i] === "/") {
861+
i++;
862+
}
863+
}
864+
}
810865

811-
var parts = path.split(/\/+/);
812866
for (var part, up = 0, i = parts.length - 1; i >= 0; i--) {
813867
part = parts[i];
814868
if (part === '.') {
@@ -839,7 +893,7 @@ return /******/ (function(modules) { // webpackBootstrap
839893
return urlGenerate(url);
840894
}
841895
return path;
842-
}
896+
});
843897
exports.normalize = normalize;
844898

845899
/**

dist/source-map.min.js

Lines changed: 3287 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/source-map.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/test/test_api.js

Lines changed: 58 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/test/test_array_set.js

Lines changed: 58 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/test/test_dog_fooding.js

Lines changed: 58 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/test/test_source_map_consumer.js

Lines changed: 58 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/test/test_source_map_generator.js

Lines changed: 58 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/test/test_source_node.js

Lines changed: 58 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)