Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
src: simplify loop arithmetic in GetCPUInfo
Cache the repeated operations and reuse; potentially generating
efficient code in some platforms, and improving readability.
  • Loading branch information
gireeshpunathil committed Feb 18, 2019
commit 80bb198947680b1ea5ab0409fc973cec036ea0bc
15 changes: 8 additions & 7 deletions src/node_os.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,15 @@ static void GetCPUInfo(const FunctionCallbackInfo<Value>& args) {
// [model, speed, (5 entries of cpu_times), model2, speed2, ...]
std::vector<Local<Value>> result(count * 7);
for (int i = 0; i < count; i++) {
int j = i * 7;
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);
Expand Down