GeezerVison is showing github.com — os: improve network interface performance · nodejs/node@594bb9d
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/os.js +21-12Lines changed: 21 additions & 12 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -28,7 +28,6 @@ const { |
28 | 28 | ObjectDefineProperties, |
29 | 29 | StringPrototypeEndsWith, |
30 | 30 | StringPrototypeSlice, |
31 | | - StringPrototypeSplit, |
32 | 31 | SymbolToPrimitive, |
33 | 32 | } = primordials; |
34 | 33 |
|
@@ -225,28 +224,38 @@ function getCIDR(address, netmask, family) { |
225 | 224 | let range = 10; |
226 | 225 | let groupLength = 8; |
227 | 226 | let hasZeros = false; |
| 227 | + let lastPos = 0; |
228 | 228 |
|
229 | 229 | if (family === 'IPv6') { |
230 | 230 | split = ':'; |
231 | 231 | range = 16; |
232 | 232 | groupLength = 16; |
233 | 233 | } |
234 | 234 |
|
235 | | - const parts = StringPrototypeSplit(netmask, split); |
236 | | - for (let i = 0; i < parts.length; i++) { |
237 | | - if (parts[i] !== '') { |
238 | | - const binary = NumberParseInt(parts[i], range); |
239 | | - const tmp = countBinaryOnes(binary); |
240 | | - ones += tmp; |
| 235 | + for (let i = 0; i < netmask.length; i++) { |
| 236 | + if (netmask[i] !== split) { |
| 237 | + if (i + 1 < netmask.length) { |
| 238 | + continue; |
| 239 | + } |
| 240 | + i++; |
| 241 | + } |
| 242 | + const part = StringPrototypeSlice(netmask, lastPos, i); |
| 243 | + lastPos = i + 1; |
| 244 | + if (part !== '') { |
241 | 245 | if (hasZeros) { |
242 | | - if (tmp !== 0) { |
| 246 | + if (part !== '0') { |
243 | 247 | return null; |
244 | 248 | } |
245 | | - } else if (tmp !== groupLength) { |
246 | | - if ((binary & 1) !== 0) { |
247 | | - return null; |
| 249 | + } else { |
| 250 | + const binary = NumberParseInt(part, range); |
| 251 | + const binaryOnes = countBinaryOnes(binary); |
| 252 | + ones += binaryOnes; |
| 253 | + if (binaryOnes !== groupLength) { |
| 254 | + if ((binary & 1) !== 0) { |
| 255 | + return null; |
| 256 | + } |
| 257 | + hasZeros = true; |
248 | 258 | } |
249 | | - hasZeros = true; |
250 | 259 | } |
251 | 260 | } |
252 | 261 | } |
|