diff options
author | Gireesh Punathil <gpunathi@in.ibm.com> | 2019-02-18 16:35:40 +0300 |
---|---|---|
committer | Daniel Bevenius <daniel.bevenius@gmail.com> | 2019-02-21 10:45:40 +0300 |
commit | e51da1fcadc822fb514cd6b32e932d7c0c3239a7 (patch) | |
tree | 3f3be517ff6654480786fb76ab79c60537ba1557 /src/node_os.cc | |
parent | 24f3f1160659ebb83416a2c779abf9d0e87ed0d6 (diff) |
src: simplify loop arithmetic in `GetCPUInfo`
Cache the repeated operations and reuse; potentially generating
efficient code in some platforms, and improving readability.
PR-URL: https://github.com/nodejs/node/pull/26183
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/node_os.cc')
-rw-r--r-- | src/node_os.cc | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/node_os.cc b/src/node_os.cc index fa27b7bac51..1d3680a6322 100644 --- a/src/node_os.cc +++ b/src/node_os.cc @@ -120,15 +120,15 @@ static void GetCPUInfo(const FunctionCallbackInfo<Value>& args) { // The array is in the format // [model, speed, (5 entries of cpu_times), model2, speed2, ...] std::vector<Local<Value>> result(count * 7); - for (int i = 0; i < count; i++) { + for (int i = 0, j = 0; i < count; i++) { uv_cpu_info_t* ci = cpu_infos + i; - result[i * 7] = OneByteString(isolate, ci->model); - result[i * 7 + 1] = Number::New(isolate, ci->speed); - result[i * 7 + 2] = Number::New(isolate, ci->cpu_times.user); - result[i * 7 + 3] = Number::New(isolate, ci->cpu_times.nice); - result[i * 7 + 4] = Number::New(isolate, ci->cpu_times.sys); - result[i * 7 + 5] = Number::New(isolate, ci->cpu_times.idle); - result[i * 7 + 6] = Number::New(isolate, ci->cpu_times.irq); + result[j++] = OneByteString(isolate, ci->model); + result[j++] = Number::New(isolate, ci->speed); + result[j++] = Number::New(isolate, ci->cpu_times.user); + result[j++] = Number::New(isolate, ci->cpu_times.nice); + result[j++] = Number::New(isolate, ci->cpu_times.sys); + result[j++] = Number::New(isolate, ci->cpu_times.idle); + result[j++] = Number::New(isolate, ci->cpu_times.irq); } uv_free_cpu_info(cpu_infos, count); |