Skip to content

Commit c061c33

Browse files
authored
reduce number of calls to Map
1 parent 648d78d commit c061c33

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

lib/util/identifier.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,20 @@ exports.makePathsRelative = (context, identifier, cache) => {
1919
if(!cache) return _makePathsRelative(context, identifier);
2020

2121
const relativePaths = cache.relativePaths || (cache.relativePaths = new Map());
22-
if(!relativePaths.has(context)) {
23-
relativePaths.set(context, new Map());
24-
}
2522

26-
const contextCache = relativePaths.get(context);
23+
let cachedResult;
24+
let contextCache = relativePaths.get(context)
25+
if(typeof contextCache === "undefined") {
26+
relativePaths.set(context, contextCache = new Map());
27+
} else {
28+
cachedResult = contextCache.get(identifier)
29+
}
2730

28-
if(contextCache.has(identifier)) {
29-
return contextCache.get(identifier);
31+
if(typeof cachedResult !== "undefined") {
32+
return cachedResult;
3033
} else {
31-
let relativePath = _makePathsRelative(context, identifier);
34+
const relativePath = _makePathsRelative(context, identifier);
3235
contextCache.set(identifier, relativePath);
3336
return relativePath;
3437
}
35-
3638
};

0 commit comments

Comments
 (0)