From 086c044dc34dfc0f74fbe41f4ecb402b2cd34884 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:13:33 +0200 Subject: Merging upstream version 125.0.1. Signed-off-by: Daniel Baumann --- .../client/debugger/src/reducers/sources-tree.js | 26 +++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'devtools/client/debugger/src/reducers/sources-tree.js') diff --git a/devtools/client/debugger/src/reducers/sources-tree.js b/devtools/client/debugger/src/reducers/sources-tree.js index 0f0e8dadb3..ee8a8d0ca0 100644 --- a/devtools/client/debugger/src/reducers/sources-tree.js +++ b/devtools/client/debugger/src/reducers/sources-tree.js @@ -25,6 +25,11 @@ const IGNORED_EXTENSIONS = ["css", "svg", "png"]; import { isPretty, getRawSourceURL } from "../utils/source"; import { prefs } from "../utils/prefs"; +const lazy = {}; +ChromeUtils.defineESModuleGetters(lazy, { + BinarySearch: "resource://gre/modules/BinarySearch.sys.mjs", +}); + export function initialSourcesTreeState() { return { // List of all Thread Tree Items. @@ -224,8 +229,10 @@ function addThread(state, thread) { // (this is also used by sortThreadItems to sort the thread as a Tree in the Browser Toolbox) threadItem.thread = thread; - // We have to re-sort all threads because of the new `thread` attribute on current thread item - state.threadItems.sort(sortThreadItems); + // We have to remove and re-insert the thread as its order will be based on the newly set `thread` attribute + state.threadItems = [...state.threadItems]; + state.threadItems.splice(state.threadItems.indexOf(threadItem), 1); + addSortedItem(state.threadItems, threadItem, sortThreadItems); } } @@ -303,13 +310,12 @@ function isSourceVisibleInSourceTree( * The already sorted into which a value should be added. * @param {any} newValue * The value to add in the array while keeping the array sorted. - * @param {Function} sortFunction + * @param {Function} comparator * A function to compare two array values and their ordering. * Follow same behavior as Array sorting function. */ -function addSortedItem(array, newValue, sortFunction) { - let index = array.findIndex(value => sortFunction(value, newValue) === 1); - index = index >= 0 ? index : array.length; +function addSortedItem(array, newValue, comparator) { + const index = lazy.BinarySearch.insertionIndexOf(comparator, array, newValue); array.splice(index, 0, newValue); } @@ -396,12 +402,12 @@ function sortItems(a, b) { return -1; } else if (b.type == "directory" && a.type == "source") { return 1; + } else if (a.type == "group" && b.type == "group") { + return a.groupName.localeCompare(b.groupName); } else if (a.type == "directory" && b.type == "directory") { return a.path.localeCompare(b.path); } else if (a.type == "source" && b.type == "source") { - return a.source.displayURL.filename.localeCompare( - b.source.displayURL.filename - ); + return a.source.longName.localeCompare(b.source.longName); } return 0; } @@ -447,7 +453,7 @@ function sortThreadItems(a, b) { if (a.thread.processID > b.thread.processID) { return 1; } else if (a.thread.processID < b.thread.processID) { - return 0; + return -1; } // Order the frame targets and the worker targets by their target name -- cgit v1.2.3