mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 15:23:51 +00:00
Bug 1170258 - Add cache of node style module resolutions. r=gkrizsanits
MozReview-Commit-ID: 2fb8aWYzs5L --HG-- extra : transplant_source : %B7%02R%CF%83%81%ABTd%F0%8F%F8%3C%F8%3F%92%2C%8B%99P
This commit is contained in:
parent
afa55c6cd9
commit
f2b5928950
@ -468,7 +468,25 @@ const nodeResolve = iced(function nodeResolve(id, requirer, { rootURI }) {
|
||||
// with `resolveURI` -- if during runtime, then `resolve` will throw.
|
||||
return void 0;
|
||||
});
|
||||
Loader.nodeResolve = nodeResolve;
|
||||
|
||||
// String (`${rootURI}:${requirer}:${id}`) -> resolvedPath
|
||||
Loader.nodeResolverCache = new Map();
|
||||
|
||||
const nodeResolveWithCache = iced(function cacheNodeResolutions(id, requirer, { rootURI }) {
|
||||
// Compute the cache key based on current arguments.
|
||||
let cacheKey = `${rootURI || ""}:${requirer}:${id}`;
|
||||
|
||||
// Try to get the result from the cache.
|
||||
if (Loader.nodeResolverCache.has(cacheKey)) {
|
||||
return Loader.nodeResolverCache.get(cacheKey);
|
||||
}
|
||||
|
||||
// Resolve and cache if it is not in the cache yet.
|
||||
let result = nodeResolve(id, requirer, { rootURI });
|
||||
Loader.nodeResolverCache.set(cacheKey, result);
|
||||
return result;
|
||||
});
|
||||
Loader.nodeResolve = nodeResolveWithCache;
|
||||
|
||||
// Attempts to load `path` and then `path.js`
|
||||
// Returns `path` with valid file, or `undefined` otherwise
|
||||
@ -784,6 +802,9 @@ Loader.Module = Module;
|
||||
// Takes `loader`, and unload `reason` string and notifies all observers that
|
||||
// they should cleanup after them-self.
|
||||
const unload = iced(function unload(loader, reason) {
|
||||
// Clear the nodeResolverCache when the loader is unloaded.
|
||||
Loader.nodeResolverCache.clear();
|
||||
|
||||
// subject is a unique object created per loader instance.
|
||||
// This allows any code to cleanup on loader unload regardless of how
|
||||
// it was loaded. To handle unload for specific loader subject may be
|
||||
|
Loading…
Reference in New Issue
Block a user