|
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 (this.#kind === 'value') { |
| 288 | + if (!isKey) ArrayPrototypePush(output, values[i]); |
| 289 | + } else if (!isKey) ArrayPrototypePush(output, [values[i - 1], values[i]]); |
| 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 ')} }`; |
|
0 commit comments