Skip to content

url: add urlSearchParams.sort()

The URL Standard requires sort() to be stable, which precludes us from using the V8-native sort() function.

I originally wanted to make the function a simple insertion sort only, but I realized it had the potential for a DoS attack because of its nature of being O(n2).

The algorithm for the function follows the norm: insertion sort for small arrays, divide-and-conquer (in this case, a stable merge sort) for larger arrays. In this specific case, the cutoff is set at 59 items, though if performance improvements are made to either sort the cutoff may be adjusted.

Fixes: #10760 (closed) Ref: whatwg/url#26 Ref: whatwg/url#199 Ref: w3c/web-platform-tests#4531

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

url

Merge request reports

Loading