diff --git a/index.js b/index.js index 32a48ea..b37e253 100644 --- a/index.js +++ b/index.js @@ -1,11 +1,5 @@ var path = require('path'); - -var clone; -try { - clone = require('node-v8-clone').clone; -} catch(e) { - clone = require('lodash').clone; -} +var clone = require('lodash').clone; var cloneStats = require('clone-stats'); var cloneBuffer = require('./lib/cloneBuffer'); var isBuffer = require('./lib/isBuffer'); @@ -76,10 +70,8 @@ File.prototype.clone = function(opt) { if (this.isStream()) { file.contents = this.contents.pipe(new Stream.PassThrough()); this.contents = this.contents.pipe(new Stream.PassThrough()); - } else if (opt.contents && this.isBuffer()) { - file.contents = cloneBuffer(this.contents); - } else { - file.contents = this.contents; + } else if (this.isBuffer()) { + file.contents = opt.contents ? cloneBuffer(this.contents) : this.contents; } // clone our custom properties diff --git a/package.json b/package.json index 080334d..d9a92ef 100644 --- a/package.json +++ b/package.json @@ -22,9 +22,6 @@ "lodash.templatesettings": "^2.4.1", "event-stream": "^3.1.0" }, - "optionalDependencies": { - "node-v8-clone": "~0.6.2" - }, "scripts": { "test": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter spec && jshint .", "coveralls": "istanbul cover _mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage" diff --git a/perf/clone.js b/perf/clone.js new file mode 100644 index 0000000..4df8578 --- /dev/null +++ b/perf/clone.js @@ -0,0 +1,59 @@ +var File = require('../'); + +var contents = new Buffer('blah blah blah'); + +var originalFile = new File({ + path: 'yo.coffee', + contents: contents +}); + +// simulate some history +originalFile.path = 'yo.js'; +originalFile.path = 'yo.js'; +originalFile.path = 'yo.js'; +originalFile.path = 'yo.js'; +originalFile.path = 'yo.js'; + +originalFile.ast = { + a: { + b: { + c: { +a: { + b: { + c: { +a: { + b: { + c: { +a: { + b: { + c: { +a: { + b: { + c: { +a: { + b: { + c: { + + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } +}; + +for (var i = 0; i < 10000; i++) { + originalFile.clone(true).ast; +} \ No newline at end of file diff --git a/test/File.js b/test/File.js index 61a8286..fd8832d 100644 --- a/test/File.js +++ b/test/File.js @@ -2,32 +2,12 @@ var Stream = require('stream'); var fs = require('fs'); var path = require('path'); var es = require('event-stream'); +var File = require('../'); var should = require('should'); require('mocha'); describe('File', function() { - - describe('using node-v8-clone', function() { - var File = require('../'); - testFile(File); - }); - - describe('using lodash', function() { - delete require.cache[path.join(__dirname, '../index.js')]; - var clonePath = path.join(__dirname, '../node_modules/node-v8-clone/lib/clone.js'); - var exports = require.cache[clonePath].exports; - // test lodash when node-v8-clone is not found - require.cache[clonePath].exports = undefined; - after(function() { - require.cache[clonePath].exports = exports; - }); - var File = require('../'); - testFile(File); - }); -}); - -function testFile(File) { describe('constructor()', function() { it('should default cwd to process.cwd', function(done) { var file = new File(); @@ -755,4 +735,4 @@ function testFile(File) { }).should.throw('path should be string'); }); }); -} +});