summaryrefslogtreecommitdiff
path: root/lib/os.js
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2018-11-09 12:22:30 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2018-11-14 02:59:45 +0800
commit51cea618e21ba88bc20feb537a72c1b831a94b46 (patch)
tree8a28c72d47628308c9baf51af6d75379197de420 /lib/os.js
parent8c60d931f2046c1a552bed1e0d5d84f731204770 (diff)
downloadandroid-node-v8-51cea618e21ba88bc20feb537a72c1b831a94b46.tar.gz
android-node-v8-51cea618e21ba88bc20feb537a72c1b831a94b46.tar.bz2
android-node-v8-51cea618e21ba88bc20feb537a72c1b831a94b46.zip
os: do not call into JS to push values to an array in GetCPUInfo
Instead of calling into JS from C++ to push values into an array, use the new Array::New API that takes a pointer and a length directly. PR-URL: https://github.com/nodejs/node/pull/24264 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com>
Diffstat (limited to 'lib/os.js')
-rw-r--r--lib/os.js32
1 files changed, 15 insertions, 17 deletions
diff --git a/lib/os.js b/lib/os.js
index 797201c4b5..2c806908ee 100644
--- a/lib/os.js
+++ b/lib/os.js
@@ -21,7 +21,7 @@
'use strict';
-const { pushValToArrayMax, safeGetenv } = internalBinding('util');
+const { safeGetenv } = internalBinding('util');
const constants = internalBinding('constants').os;
const { deprecate } = require('internal/util');
const isWindows = process.platform === 'win32';
@@ -82,31 +82,29 @@ const getNetworkInterfacesDepMsg =
'os.getNetworkInterfaces is deprecated. Use os.networkInterfaces instead.';
const avgValues = new Float64Array(3);
-const cpuValues = new Float64Array(6 * pushValToArrayMax);
function loadavg() {
getLoadAvg(avgValues);
return [avgValues[0], avgValues[1], avgValues[2]];
}
-function addCPUInfo() {
- for (var i = 0, c = 0; i < arguments.length; ++i, c += 6) {
- this[this.length] = {
- model: arguments[i],
- speed: cpuValues[c],
+function cpus() {
+ 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: cpuValues[c + 1],
- nice: cpuValues[c + 2],
- sys: cpuValues[c + 3],
- idle: cpuValues[c + 4],
- irq: cpuValues[c + 5]
+ user: data[i + 2],
+ nice: data[i + 3],
+ sys: data[i + 4],
+ idle: data[i + 5],
+ irq: data[i + 6]
}
- };
+ });
}
-}
-
-function cpus() {
- return getCPUs(addCPUInfo, cpuValues, []);
+ return result;
}
function arch() {