Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: simplify loop arithmetic in GetCPUInfo #26183

Closed
wants to merge 5 commits into from

Conversation

gireeshpunathil
Copy link
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 nodejs-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
src/node_os.cc Outdated Show resolved Hide resolved
src/node_os.cc Outdated Show resolved Hide resolved
@gireeshpunathil
Copy link
Member Author

Copy link
Member

@ZYSzys ZYSzys left a comment

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

function cpus() {
// [] is a bugfix for a regression introduced in 51cea61
const data = getCPUs() || [];
const result = [];
for (var i = 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]
}
});
}
return result;
}

@gireeshpunathil
Copy link
Member Author

@ZYSzys - done, thanks!

lib/os.js Outdated Show resolved Hide resolved
lib/os.js Show resolved Hide resolved
@danbev
Copy link
Contributor

danbev commented Feb 21, 2019

Landed in e51da1f.

@danbev danbev 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>
@BridgeAR BridgeAR 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 free to 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++. os Issues and PRs related to the os subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants