diff options
Diffstat (limited to 'src/data/composite')
-rw-r--r-- | src/data/composite/data/withSortedList.js | 27 |
1 files changed, 5 insertions, 22 deletions
diff --git a/src/data/composite/data/withSortedList.js b/src/data/composite/data/withSortedList.js index fc0ed9e9..6b67f57e 100644 --- a/src/data/composite/data/withSortedList.js +++ b/src/data/composite/data/withSortedList.js @@ -59,13 +59,11 @@ export default templateCompositeFrom({ const symbols = []; const symbolToIndex = new Map(); - const indexToSymbol = new Map(); for (const index of originalIndices) { const symbol = Symbol(); symbols.push(symbol); symbolToIndex.set(symbol, index); - indexToSymbol.set(index, symbol); } const equalSymbols = new Map(); @@ -96,38 +94,23 @@ export default templateCompositeFrom({ }); const stableSortIndices = []; + const unstableSortIndices = []; const sortedList = []; - const symbolToStable = new Map(); - const stableToUnstable = new Map(); + let unstableIndex = 0; for (const [stableIndex, symbol] of symbols.entries()) { const sourceIndex = symbolToIndex.get(symbol); stableSortIndices.push(sourceIndex); - symbolToStable.set(symbol, stableIndex); sortedList.push(list[sourceIndex]); - if (stableIndex === 0) { - stableToUnstable.set(stableIndex, 0); - continue; + if (stableIndex > 0 && !isEqual(symbol, symbols[stableIndex - 1])) { + unstableIndex++; } - const previousUnstable = stableToUnstable.get(stableIndex - 1); - - const newUnstable = - (isEqual(symbol, symbols[stableIndex - 1]) - ? previousUnstable - : previousUnstable + 1); - - stableToUnstable.set(stableIndex, newUnstable); + unstableSortIndices[sourceIndex] = unstableIndex; } - const unstableSortIndices = - originalIndices - .map(index => indexToSymbol.get(index)) - .map(symbol => symbolToStable.get(symbol)) - .map(stable => stableToUnstable.get(stable)); - return continuation({ ['#sortedList']: sortedList, ['#sortIndices']: stableSortIndices, |