diff options
author | James Pickard <james.pickard@gmail.com> | 2014-02-27 15:45:18 -0500 |
---|---|---|
committer | Trevor Norris <trev.norris@gmail.com> | 2014-03-31 15:02:17 -0700 |
commit | e9ce8fc82a6d12e790511b62852e820d8be03186 (patch) | |
tree | 4ba7a41c95eaf0a484b716602096d3fef7cbeb42 /lib/fs.js | |
parent | 5d2aef17ee56fbbf415ca1e3034cdb02cd97117c (diff) | |
download | nodejs-e9ce8fc82a6d12e790511b62852e820d8be03186.tar.gz nodejs-e9ce8fc82a6d12e790511b62852e820d8be03186.tar.bz2 nodejs-e9ce8fc82a6d12e790511b62852e820d8be03186.zip |
fs: improve performance of all stat functions
By building the fs.Stats object in JS, which is returned by all fs stat
functions, calls to v8::Object::Set() are removed. This also includes
creating all associated Date objects in JS, rather than using
v8::Date::New(). Both these changes have significant performance gains.
Note that the returned value from fs.stat changes slightly for non-POSIX
systems. Whereas before the stats object would be missing blocks and
blksize keys, it now has these keys with undefined as the value.
Signed-off-by: Trevor Norris <trev.norris@gmail.com>
Diffstat (limited to 'lib/fs.js')
-rw-r--r-- | lib/fs.js | 33 |
1 files changed, 32 insertions, 1 deletions
@@ -117,7 +117,38 @@ function nullCheck(path, callback) { return true; } -fs.Stats = binding.Stats; +// Static method to set the stats properties on a Stats object. +fs.Stats = function( + dev, + mode, + nlink, + uid, + gid, + rdev, + ino, + size, + blocks, + atim_msec, + mtim_msec, + ctim_msec, + birthtim_msec) { + this.dev = dev; + this.mode = mode; + this.nlink = nlink; + this.uid = uid; + this.gid = gid; + this.rdev = rdev; + this.ino = ino; + this.size = size; + this.blocks = blocks; + this.atime = new Date(atim_msec); + this.mtime = new Date(mtim_msec); + this.ctime = new Date(ctim_msec); + this.birthtime = new Date(birthtim_msec); +}; + +// Create a C++ binding to the function which creates a Stats object. +binding.FSInitialize(fs.Stats); fs.Stats.prototype._checkModeProperty = function(property) { return ((this.mode & constants.S_IFMT) === property); |