From a774707e312a01ff6892a5d7fdc2df5281f1603c Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 6 Nov 2021 10:10:12 +0100 Subject: [PATCH] Remove the `moveToEndOfArray` helper function, since it's unused With the previous patch, this helper function is no longer used and keeping it around will simply increase the size of the builds. This removal is purposely done *separately*, to make it easy to revert the patch in the future if this helper function would become useful again. --- test/unit/ui_utils_spec.js | 41 -------------------------------------- web/ui_utils.js | 22 -------------------- 2 files changed, 63 deletions(-) diff --git a/test/unit/ui_utils_spec.js b/test/unit/ui_utils_spec.js index 5eb21330c..4b7bf147d 100644 --- a/test/unit/ui_utils_spec.js +++ b/test/unit/ui_utils_spec.js @@ -21,7 +21,6 @@ import { getVisibleElements, isPortraitOrientation, isValidRotation, - moveToEndOfArray, parseQueryString, waitOnEventOrTimeout, WaitOnType, @@ -864,44 +863,4 @@ describe("ui_utils", function () { }); }); }); - - describe("moveToEndOfArray", function () { - it("works on empty arrays", function () { - const data = []; - moveToEndOfArray(data, function () {}); - expect(data).toEqual([]); - }); - - it("works when moving everything", function () { - const data = [1, 2, 3, 4, 5]; - moveToEndOfArray(data, function () { - return true; - }); - expect(data).toEqual([1, 2, 3, 4, 5]); - }); - - it("works when moving some things", function () { - const data = [1, 2, 3, 4, 5]; - moveToEndOfArray(data, function (x) { - return x % 2 === 0; - }); - expect(data).toEqual([1, 3, 5, 2, 4]); - }); - - it("works when moving one thing", function () { - const data = [1, 2, 3, 4, 5]; - moveToEndOfArray(data, function (x) { - return x === 1; - }); - expect(data).toEqual([2, 3, 4, 5, 1]); - }); - - it("works when moving nothing", function () { - const data = [1, 2, 3, 4, 5]; - moveToEndOfArray(data, function (x) { - return x === 0; - }); - expect(data).toEqual([1, 2, 3, 4, 5]); - }); - }); }); diff --git a/web/ui_utils.js b/web/ui_utils.js index c769bf3f0..72ad3097b 100644 --- a/web/ui_utils.js +++ b/web/ui_utils.js @@ -906,27 +906,6 @@ class ProgressBar { } } -/** - * Moves all elements of an array that satisfy condition to the end of the - * array, preserving the order of the rest. - */ -function moveToEndOfArray(arr, condition) { - const moved = [], - len = arr.length; - let write = 0; - for (let read = 0; read < len; ++read) { - if (condition(arr[read])) { - moved.push(arr[read]); - } else { - arr[write] = arr[read]; - ++write; - } - } - for (let read = 0; write < len; ++read, ++write) { - arr[write] = moved[read]; - } -} - /** * Get the active or focused element in current DOM. * @@ -1031,7 +1010,6 @@ export { MAX_AUTO_SCALE, MAX_SCALE, MIN_SCALE, - moveToEndOfArray, noContextMenuHandler, normalizeWheelEventDelta, normalizeWheelEventDirection,