Skip to content

src: simplify loop arithmetic in GetCPUInfo - #26183

Closed
gireeshpunathil wants to merge 5 commits into
nodejs:masterfrom
gireeshpunathil:arrayslot
Closed

src: simplify loop arithmetic in GetCPUInfo#26183
gireeshpunathil wants to merge 5 commits into
nodejs:masterfrom
gireeshpunathil:arrayslot

Conversation

@gireeshpunathil

Copy link
Copy Markdown
Member

Cache the repeated operations and reuse; potentially generating
efficient code in some platforms, and improving readability.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

Cache the repeated operations and reuse; potentially generating
efficient code in some platforms, and improving readability.
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-botnodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. os Issues and PRs related to the os subsystem. labels Feb 18, 2019
Comment threadsrc/node_os.cc Outdated
Comment threadsrc/node_os.cc Outdated
@gireeshpunathil

Copy link
Copy Markdown
MemberAuthor

@ZYSzysZYSzys left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are here, how about do the same thing on js land too for consistency ?

node/lib/os.js

Lines 88 to 106 in 8375c70

functioncpus(){
// [] is a bugfix for a regression introduced in 51cea61
constdata=getCPUs()||[];
constresult=[];
for(vari=0;i<data.length;i+=7){
result.push({
model: data[i],
speed: data[i+1],
times: {
user: data[i+2],
nice: data[i+3],
sys: data[i+4],
idle: data[i+5],
irq: data[i+6]
}
});
}
returnresult;
}

@gireeshpunathil

Copy link
Copy Markdown
MemberAuthor

@ZYSzys - done, thanks!

Comment threadlib/os.js Outdated
Comment threadlib/os.js
@danbev

Copy link
Copy Markdown
Contributor

Landed in e51da1f.

@danbevdanbev closed this Feb 21, 2019
danbev pushed a commit that referenced this pull request Feb 21, 2019
Cache the repeated operations and reuse; potentially generating
efficient code in some platforms, and improving readability.
PR-URL: #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>
addaleax pushed a commit that referenced this pull request Feb 21, 2019
Cache the repeated operations and reuse; potentially generating
efficient code in some platforms, and improving readability.
PR-URL: #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>
@BridgeARBridgeAR mentioned this pull request Feb 26, 2019
rvagg pushed a commit that referenced this pull request Feb 28, 2019
Cache the repeated operations and reuse; potentially generating
efficient code in some platforms, and improving readability.
PR-URL: #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>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++Issues and PRs that require attention from people who are familiar with C++.osIssues and PRs related to the os subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants

@gireeshpunathil@nodejs-github-bot@danbev@apapirovski@mscdex@jasnell@richardlau@BridgeAR@ZYSzys