MCPcopy Index your code
hub / github.com/nodejs/node / sort

Method sort

lib/internal/url.js:649–696  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

647 }
648
649 sort() {
650 if (typeof this !== 'object' || this === null || !(#searchParams in this))
651 throw new ERR_INVALID_THIS('URLSearchParams');
652
653 const a = this.#searchParams;
654 const len = a.length;
655
656 if (len <= 2) {
657 // Nothing needs to be done.
658 } else if (len < 100) {
659 // 100 is found through testing.
660 // Simple stable in-place insertion sort
661 // Derived from v8/src/js/array.js
662 for (let i = 2; i < len; i += 2) {
663 const curKey = a[i];
664 const curVal = a[i + 1];
665 let j;
666 for (j = i - 2; j >= 0; j -= 2) {
667 if (a[j] > curKey) {
668 a[j + 2] = a[j];
669 a[j + 3] = a[j + 1];
670 } else {
671 break;
672 }
673 }
674 a[j + 2] = curKey;
675 a[j + 3] = curVal;
676 }
677 } else {
678 // Bottom-up iterative stable merge sort
679 const lBuffer = new Array(len);
680 const rBuffer = new Array(len);
681 for (let step = 2; step < len; step *= 2) {
682 for (let start = 0; start < len - 2; start += 2 * step) {
683 const mid = start + step;
684 let end = mid + step;
685 end = end < len ? end : len;
686 if (mid > end)
687 continue;
688 merge(a, start, mid, end, lBuffer, rBuffer);
689 }
690 }
691 }
692
693 if (this.#context) {
694 setURLSearchParamsModified(this.#context);
695 }
696 }
697
698 // https://heycam.github.io/webidl/#es-iterators
699 // Define entries here rather than [Symbol.iterator] as the function name

Callers 15

mainFunction · 0.95
safeUrlFunction · 0.95
ListTestsMethod · 0.80
MainFunction · 0.80
ParseArgumentsFunction · 0.80
list_templatesMethod · 0.80
find_all_gyptest_filesFunction · 0.80
get_stringMethod · 0.80
PrettyPrintNodeFunction · 0.80
CleanupVcprojFunction · 0.80
__init__Method · 0.80
WriteMethod · 0.80

Calls 1

mergeFunction · 0.70

Tested by 8

ListTestsMethod · 0.64
MainFunction · 0.64
find_all_gyptest_filesFunction · 0.64
testFunction · 0.64
testFunction · 0.64
clean_json_outputFunction · 0.64
_list_test_filenamesMethod · 0.64
testFunction · 0.64