@@ -495,26 +495,37 @@ class URLSearchParams {
|
495 | 495 | |
496 | 496 | const list = this.#searchParams; |
497 | 497 | name = StringPrototypeToWellFormed(`${name}`); |
| 498 | +const { length } = list; |
| 499 | +let write = 0; |
498 | 500 | |
499 | 501 | if (value !== undefined) { |
500 | 502 | value = StringPrototypeToWellFormed(`${value}`); |
501 | | -for (let i = 0; i < list.length;) { |
| 503 | +for (let i = 0; i < length; i += 2) { |
502 | 504 | if (list[i] === name && list[i + 1] === value) { |
503 | | -list.splice(i, 2); |
504 | | -} else { |
505 | | -i += 2; |
| 505 | +continue; |
| 506 | +} |
| 507 | +if (write !== i) { |
| 508 | +list[write] = list[i]; |
| 509 | +list[write + 1] = list[i + 1]; |
506 | 510 | } |
| 511 | +write += 2; |
507 | 512 | } |
508 | 513 | } else { |
509 | | -for (let i = 0; i < list.length;) { |
| 514 | +for (let i = 0; i < length; i += 2) { |
510 | 515 | if (list[i] === name) { |
511 | | -list.splice(i, 2); |
512 | | -} else { |
513 | | -i += 2; |
| 516 | +continue; |
| 517 | +} |
| 518 | +if (write !== i) { |
| 519 | +list[write] = list[i]; |
| 520 | +list[write + 1] = list[i + 1]; |
514 | 521 | } |
| 522 | +write += 2; |
515 | 523 | } |
516 | 524 | } |
517 | 525 | |
| 526 | +if (write !== length) |
| 527 | +list.length = write; |
| 528 | + |
518 | 529 | if (this.#context) { |
519 | 530 | setURLSearchParamsModified(this.#context); |
520 | 531 | } |
@@ -594,24 +605,34 @@ class URLSearchParams {
|
594 | 605 | const list = this.#searchParams; |
595 | 606 | name = StringPrototypeToWellFormed(`${name}`); |
596 | 607 | value = StringPrototypeToWellFormed(`${value}`); |
| 608 | +const { length } = list; |
597 | 609 | |
598 | 610 | // If there are any name-value pairs whose name is `name`, in `list`, set |
599 | 611 | // the value of the first such name-value pair to `value` and remove the |
600 | 612 | // others. |
601 | 613 | let found = false; |
602 | | -for (let i = 0; i < list.length;) { |
| 614 | +let write = 0; |
| 615 | +for (let i = 0; i < length; i += 2) { |
603 | 616 | const cur = list[i]; |
| 617 | +let keep = true; |
604 | 618 | if (cur === name) { |
605 | 619 | if (!found) { |
606 | | -list[i + 1] = value; |
| 620 | +list[write] = cur; |
| 621 | +list[write + 1] = value; |
607 | 622 | found = true; |
608 | | -i += 2; |
609 | 623 | } else { |
610 | | -list.splice(i, 2); |
| 624 | +keep = false; |
611 | 625 | } |
612 | | -} else { |
613 | | -i += 2; |
| 626 | +} else if (write !== i) { |
| 627 | +list[write] = cur; |
| 628 | +list[write + 1] = list[i + 1]; |
614 | 629 | } |
| 630 | +if (keep) |
| 631 | +write += 2; |
| 632 | +} |
| 633 | + |
| 634 | +if (found && write !== length) { |
| 635 | +list.length = write; |
615 | 636 | } |
616 | 637 | |
617 | 638 | // Otherwise, append a new name-value pair whose name is `name` and value |
|