Skip to content

Commit c442d89

Browse files
aduh95targos
authored andcommitted
os: refactor to use more primordials
PR-URL: #36284 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 41d74a4 commit c442d89

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

lib/os.js

+12-7
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@
2222
'use strict';
2323

2424
const {
25+
ArrayPrototypePush,
2526
Float64Array,
2627
NumberParseInt,
2728
ObjectDefineProperties,
29+
StringPrototypeEndsWith,
30+
StringPrototypeSlice,
31+
StringPrototypeSplit,
2832
SymbolToPrimitive,
2933
} = primordials;
3034

@@ -132,7 +136,7 @@ function cpus() {
132136
const result = [];
133137
let i = 0;
134138
while (i < data.length) {
135-
result.push({
139+
ArrayPrototypePush(result, {
136140
model: data[i++],
137141
speed: data[i++],
138142
times: {
@@ -172,15 +176,16 @@ function tmpdir() {
172176
path = process.env.TEMP ||
173177
process.env.TMP ||
174178
(process.env.SystemRoot || process.env.windir) + '\\temp';
175-
if (path.length > 1 && path.endsWith('\\') && !path.endsWith(':\\'))
176-
path = path.slice(0, -1);
179+
if (path.length > 1 && StringPrototypeEndsWith(path, '\\') &&
180+
!StringPrototypeEndsWith(path, ':\\'))
181+
path = StringPrototypeSlice(path, 0, -1);
177182
} else {
178183
path = safeGetenv('TMPDIR') ||
179184
safeGetenv('TMP') ||
180185
safeGetenv('TEMP') ||
181186
'/tmp';
182-
if (path.length > 1 && path.endsWith('/'))
183-
path = path.slice(0, -1);
187+
if (path.length > 1 && StringPrototypeEndsWith(path, '/'))
188+
path = StringPrototypeSlice(path, 0, -1);
184189
}
185190

186191
return path;
@@ -217,7 +222,7 @@ function getCIDR(address, netmask, family) {
217222
groupLength = 16;
218223
}
219224

220-
const parts = netmask.split(split);
225+
const parts = StringPrototypeSplit(netmask, split);
221226
for (var i = 0; i < parts.length; i++) {
222227
if (parts[i] !== '') {
223228
const binary = NumberParseInt(parts[i], range);
@@ -272,7 +277,7 @@ function networkInterfaces() {
272277

273278
const existing = result[name];
274279
if (existing !== undefined)
275-
existing.push(entry);
280+
ArrayPrototypePush(existing, entry);
276281
else
277282
result[name] = [entry];
278283
}

0 commit comments

Comments
 (0)