Skip to content

Commit

Permalink
os: refactor to use more primordials
Browse files Browse the repository at this point in the history
PR-URL: nodejs#36284
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
aduh95 authored and cjihrig committed Dec 8, 2020
1 parent a5e2ea9 commit a864d7a
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions lib/os.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@
'use strict';

const {
ArrayPrototypePush,
Float64Array,
NumberParseInt,
ObjectDefineProperties,
StringPrototypeEndsWith,
StringPrototypeSlice,
StringPrototypeSplit,
SymbolToPrimitive,
} = primordials;

Expand Down Expand Up @@ -104,7 +108,7 @@ function cpus() {
const result = [];
let i = 0;
while (i < data.length) {
result.push({
ArrayPrototypePush(result, {
model: data[i++],
speed: data[i++],
times: {
Expand Down Expand Up @@ -135,15 +139,16 @@ function tmpdir() {
path = process.env.TEMP ||
process.env.TMP ||
(process.env.SystemRoot || process.env.windir) + '\\temp';
if (path.length > 1 && path.endsWith('\\') && !path.endsWith(':\\'))
path = path.slice(0, -1);
if (path.length > 1 && StringPrototypeEndsWith(path, '\\') &&
!StringPrototypeEndsWith(path, ':\\'))
path = StringPrototypeSlice(path, 0, -1);
} else {
path = safeGetenv('TMPDIR') ||
safeGetenv('TMP') ||
safeGetenv('TEMP') ||
'/tmp';
if (path.length > 1 && path.endsWith('/'))
path = path.slice(0, -1);
if (path.length > 1 && StringPrototypeEndsWith(path, '/'))
path = StringPrototypeSlice(path, 0, -1);
}

return path;
Expand Down Expand Up @@ -177,7 +182,7 @@ function getCIDR(address, netmask, family) {
groupLength = 16;
}

const parts = netmask.split(split);
const parts = StringPrototypeSplit(netmask, split);
for (var i = 0; i < parts.length; i++) {
if (parts[i] !== '') {
const binary = NumberParseInt(parts[i], range);
Expand Down Expand Up @@ -221,7 +226,7 @@ function networkInterfaces() {

const existing = result[name];
if (existing !== undefined)
existing.push(entry);
ArrayPrototypePush(existing, entry);
else
result[name] = [entry];
}
Expand Down

0 comments on commit a864d7a

Please sign in to comment.