Skip to content

Commit

Permalink
index.js: More efficient usage of cache
Browse files Browse the repository at this point in the history
  • Loading branch information
tadatuta committed Dec 18, 2015
1 parent 30840ae commit 199c068
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ var Compiler = require('./lib/compiler').Compiler;
var _cache = {};

function getEngine(engineName) {
if (_cache[engineName]) return _cache[engineName];

var runtime = require('./lib/' + engineName);
var pathToBundle = require.resolve('./lib/' + engineName + '/bundle');
var sourceBundle = fs.readFileSync(pathToBundle, 'utf8');

runtime.source = sourceBundle;

return _cache[engineName] || (_cache[engineName] = new Compiler(runtime));
return _cache[engineName] = new Compiler(runtime);
}

module.exports = {
Expand Down

0 comments on commit 199c068

Please sign in to comment.