Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBrian White <mscdex@mscdex.net>2017-02-23 20:45:10 +0300
committerBrian White <mscdex@mscdex.net>2017-02-26 04:58:42 +0300
commit22abb39b2cfc8a462caddf0abe6a096b8562380f (patch)
treecf48a7036b5e988c8d4a93c909bab03e9c9f5388 /lib
parentefdc571a5804c8fd962e50edc0beb176f95cc092 (diff)
fs: improve performance for sync stat() functions
PR-URL: https://github.com/nodejs/node/pull/11522 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/fs.js26
1 files changed, 20 insertions, 6 deletions
diff --git a/lib/fs.js b/lib/fs.js
index d45bd82df70..3f2a3cc1ac4 100644
--- a/lib/fs.js
+++ b/lib/fs.js
@@ -131,7 +131,7 @@ function isFd(path) {
}
// Static method to set the stats properties on a Stats object.
-fs.Stats = function(
+function Stats(
dev,
mode,
nlink,
@@ -160,7 +160,8 @@ fs.Stats = function(
this.mtime = new Date(mtim_msec);
this.ctime = new Date(ctim_msec);
this.birthtime = new Date(birthtim_msec);
-};
+}
+fs.Stats = Stats;
// Create a C++ binding to the function which creates a Stats object.
binding.FSInitialize(fs.Stats);
@@ -262,7 +263,7 @@ fs.existsSync = function(path) {
try {
handleError((path = getPathFromURL(path)));
nullCheck(path);
- binding.stat(pathModule._makeLong(path));
+ binding.stat(pathModule._makeLong(path), statValues);
return true;
} catch (e) {
return false;
@@ -856,20 +857,33 @@ fs.stat = function(path, callback) {
binding.stat(pathModule._makeLong(path), req);
};
+const statValues = new Float64Array(14);
+function statsFromValues() {
+ return new Stats(statValues[0], statValues[1], statValues[2], statValues[3],
+ statValues[4], statValues[5],
+ statValues[6] < 0 ? undefined : statValues[6], statValues[7],
+ statValues[8], statValues[9] < 0 ? undefined : statValues[9],
+ statValues[10], statValues[11], statValues[12],
+ statValues[13]);
+}
+
fs.fstatSync = function(fd) {
- return binding.fstat(fd);
+ binding.fstat(fd, statValues);
+ return statsFromValues();
};
fs.lstatSync = function(path) {
handleError((path = getPathFromURL(path)));
nullCheck(path);
- return binding.lstat(pathModule._makeLong(path));
+ binding.lstat(pathModule._makeLong(path), statValues);
+ return statsFromValues();
};
fs.statSync = function(path) {
handleError((path = getPathFromURL(path)));
nullCheck(path);
- return binding.stat(pathModule._makeLong(path));
+ binding.stat(pathModule._makeLong(path), statValues);
+ return statsFromValues();
};
fs.readlink = function(path, options, callback) {