Skip to content

Commit

Permalink
Use Map/Set instead of Object.create(null)
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Jan 19, 2017
1 parent 9c8d7a2 commit 4b6323e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions lib/ava-files.js
Expand Up @@ -13,11 +13,11 @@ function handlePaths(files, excludePatterns, globOptions) {
// Convert Promise to Bluebird
files = Promise.resolve(globby(files.concat(excludePatterns), globOptions));

const searchedParents = Object.create(null);
const foundFiles = Object.create(null);
const searchedParents = new Set();
const foundFiles = new Set();

function alreadySearchingParent(dir) {
if (searchedParents[dir]) {
if (searchedParents.has(dir)) {
return true;
}

Expand All @@ -40,7 +40,7 @@ function handlePaths(files, excludePatterns, globOptions) {
return null;
}

searchedParents[file] = true;
searchedParents.add(file);

let pattern = path.join(file, '**', '*.js');

Expand All @@ -67,8 +67,8 @@ function handlePaths(files, excludePatterns, globOptions) {
})
.map(file => path.resolve(file))
.filter(file => {
const alreadyFound = foundFiles[file];
foundFiles[file] = true;
const alreadyFound = foundFiles.has(file);
foundFiles.add(file);
return !alreadyFound;
});
}
Expand Down
8 changes: 4 additions & 4 deletions lib/process-adapter.js
Expand Up @@ -62,18 +62,18 @@ if (debug.enabled) {
require('time-require'); // eslint-disable-line import/no-unassigned-import
}

const sourceMapCache = Object.create(null);
const sourceMapCache = new Map();
const cacheDir = opts.cacheDir;

exports.installSourceMapSupport = () => {
sourceMapSupport.install({
environment: 'node',
handleUncaughtExceptions: false,
retrieveSourceMap(source) {
if (sourceMapCache[source]) {
if (sourceMapCache.has(source)) {
return {
url: source,
map: fs.readFileSync(sourceMapCache[source], 'utf8')
map: fs.readFileSync(sourceMapCache.get(source), 'utf8')
};
}
}
Expand All @@ -85,7 +85,7 @@ exports.installPrecompilerHook = () => {
const precompiled = opts.precompiled[filename];

if (precompiled) {
sourceMapCache[filename] = path.join(cacheDir, precompiled + '.js.map');
sourceMapCache.set(filename, path.join(cacheDir, precompiled + '.js.map'));
return fs.readFileSync(path.join(cacheDir, precompiled + '.js'), 'utf8');
}

Expand Down

0 comments on commit 4b6323e

Please sign in to comment.