| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent af42ca5 commit a6ac8bd
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,39 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common.js'); | ||
| 3 | + const { inspect } = require('util'); | ||
| 4 | + | ||
| 5 | + const bench = common.createBenchmark(main, { | ||
| 6 | + variant: ['empty', 'small', 'medium', 'large'], | ||
| 7 | + kind: ['params', 'iterator-keys', 'iterator-values', 'iterator-entries'], | ||
| 8 | + n: [1e5], | ||
| 9 | + }); | ||
| 10 | + | ||
| 11 | + function makeParams(size) { | ||
| 12 | + const u = new URLSearchParams(); | ||
| 13 | + for (let i = 0; i < size; i++) { | ||
| 14 | + u.append('k' + i, 'v' + i); | ||
| 15 | + } | ||
| 16 | + return u; | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + function main({ variant, kind, n }) { | ||
| 20 | + const sizes = { empty: 0, small: 3, medium: 16, large: 128 }; | ||
| 21 | + const size = sizes[variant]; | ||
| 22 | + const params = makeParams(size); | ||
| 23 | + let target; | ||
| 24 | + if (kind === 'params') { | ||
| 25 | + target = params; | ||
| 26 | + } else if (kind === 'iterator-keys') { | ||
| 27 | + target = params.keys(); | ||
| 28 | + } else if (kind === 'iterator-values') { | ||
| 29 | + target = params.values(); | ||
| 30 | + } else { | ||
| 31 | + target = params.entries(); | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + bench.start(); | ||
| 35 | + for (let i = 0; i < n; i++) { | ||
| 36 | + inspect(target, { showHidden: false, depth: 2 }); | ||
| 37 | + } | ||
| 38 | + bench.end(n); | ||
| 39 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,8 +6,6 @@ const { | |||
| 6 | 6 | ArrayPrototypeJoin, | |
| 7 | 7 | ArrayPrototypeMap, | |
| 8 | 8 | ArrayPrototypePush, | |
| 9 | - ArrayPrototypeReduce, | ||
| 10 | - ArrayPrototypeSlice, | ||
| 11 | 9 | Boolean, | |
| 12 | 10 | Int8Array, | |
| 13 | 11 | IteratorPrototype, | |
@@ -281,25 +279,19 @@ class URLSearchParamsIterator { | |||
| 281 | 279 | } | |
| 282 | 280 | const index = this.#index; | |
| 283 | 281 | const values = getURLSearchParamsList(this.#target); | |
| 284 | - const output = ArrayPrototypeReduce( | ||
| 285 | - ArrayPrototypeSlice(values, index), | ||
| 286 | - (prev, cur, i) => { | ||
| 287 | - const key = i % 2 === 0; | ||
| 288 | - if (this.#kind === 'key' && key) { | ||
| 289 | - ArrayPrototypePush(prev, cur); | ||
| 290 | - } else if (this.#kind === 'value' && !key) { | ||
| 291 | - ArrayPrototypePush(prev, cur); | ||
| 292 | - } else if (this.#kind === 'key+value' && !key) { | ||
| 293 | - ArrayPrototypePush(prev, [values[index + i - 1], cur]); | ||
| 294 | - } | ||
| 295 | - return prev; | ||
| 296 | - }, | ||
| 297 | - [], | ||
| 298 | - ); | ||
| 299 | - const breakLn = StringPrototypeIncludes(inspect(output, innerOpts), '\n'); | ||
| 282 | + const output = []; | ||
| 283 | + for (let i = index; i < values.length; i++) { | ||
| 284 | + const isKey = ((i - index) % 2) === 0; | ||
| 285 | + if (this.#kind === 'key') { | ||
| 286 | + if (isKey) ArrayPrototypePush(output, values[i]); | ||
| 287 | + } else if (!isKey) { | ||
| 288 | + ArrayPrototypePush(output, this.#kind === 'value' ? values[i] : [values[i - 1], values[i]]); | ||
| 289 | + } | ||
| 290 | + } | ||
| 291 | + const hasBreak = StringPrototypeIncludes(inspect(output, innerOpts), '\n'); | ||
| 300 | 292 | const outputStrs = ArrayPrototypeMap(output, (p) => inspect(p, innerOpts)); | |
| 301 | 293 | let outputStr; | |
| 302 | - if (breakLn) { | ||
| 294 | + if (hasBreak) { | ||
| 303 | 295 | outputStr = `\n ${ArrayPrototypeJoin(outputStrs, ',\n ')}`; | |
| 304 | 296 | } else { | |
| 305 | 297 | outputStr = ` ${ArrayPrototypeJoin(outputStrs, ', ')}`; | |
@@ -456,11 +448,10 @@ class URLSearchParams { | |||
| 456 | 448 | output, | |
| 457 | 449 | `${innerInspect(list[i])} => ${innerInspect(list[i + 1])}`); | |
| 458 | 450 | ||
| 459 | - const length = ArrayPrototypeReduce( | ||
| 460 | - output, | ||
| 461 | - (prev, cur) => prev + removeColors(cur).length + separator.length, | ||
| 462 | - -separator.length, | ||
| 463 | - ); | ||
| 451 | + let length = -separator.length; | ||
| 452 | + for (let i = 0; i < output.length; i++) { | ||
| 453 | + length += removeColors(output[i]).length + separator.length; | ||
| 454 | + } | ||
| 464 | 455 | if (length > ctx.breakLength) { | |
| 465 | 456 | return `${this.constructor.name} {\n` + | |
| 466 | 457 | ` ${ArrayPrototypeJoin(output, ',\n ')} }`; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments