diff options
author | Brian White <mscdex@mscdex.net> | 2017-02-23 11:22:01 +0300 |
---|---|---|
committer | Brian White <mscdex@mscdex.net> | 2017-02-26 04:53:56 +0300 |
commit | efdc571a5804c8fd962e50edc0beb176f95cc092 (patch) | |
tree | add94880870d65e86af2f522d1f0821400486a02 /src/node_os.cc | |
parent | ee7b7f693559afa05ea42279f856b4fc2186f527 (diff) |
os: improve loadavg() performance
PR-URL: https://github.com/nodejs/node/pull/11516
Reviewed-By: Jackson Tian <shyvo1987@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Diffstat (limited to 'src/node_os.cc')
-rw-r--r-- | src/node_os.cc | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/node_os.cc b/src/node_os.cc index 97b1a1d08da..211ac3d01dd 100644 --- a/src/node_os.cc +++ b/src/node_os.cc @@ -28,8 +28,10 @@ namespace node { namespace os { using v8::Array; +using v8::ArrayBuffer; using v8::Boolean; using v8::Context; +using v8::Float64Array; using v8::FunctionCallbackInfo; using v8::Integer; using v8::Local; @@ -182,14 +184,12 @@ static void GetUptime(const FunctionCallbackInfo<Value>& args) { static void GetLoadAvg(const FunctionCallbackInfo<Value>& args) { - Environment* env = Environment::GetCurrent(args); - double loadavg[3]; + CHECK(args[0]->IsFloat64Array()); + Local<Float64Array> array = args[0].As<Float64Array>(); + CHECK_EQ(array->Length(), 3); + Local<ArrayBuffer> ab = array->Buffer(); + double* loadavg = static_cast<double*>(ab->GetContents().Data()); uv_loadavg(loadavg); - Local<Array> loads = Array::New(env->isolate(), 3); - loads->Set(0, Number::New(env->isolate(), loadavg[0])); - loads->Set(1, Number::New(env->isolate(), loadavg[1])); - loads->Set(2, Number::New(env->isolate(), loadavg[2])); - args.GetReturnValue().Set(loads); } |