Skip to content

Commit

Permalink
refactor(typescript): packages/rspack/src/util/StatsFactory (#7381)
Browse files Browse the repository at this point in the history
* refactor(typescript): packages/rspack/src/util/StatsFactory

* fix: update typing

* fix: remove unnecessary typing
  • Loading branch information
wxiaoyun authored Jul 31, 2024
1 parent 669c2f1 commit f8d3a69
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
10 changes: 2 additions & 8 deletions packages/rspack/src/stats/StatsFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,7 @@ export class StatsFactory {
h.call(comparators, context)
);
if (comparators.length > 0) {
items.sort(
// @ts-expect-error number of arguments is correct
concatComparators(...comparators)
);
items.sort(concatComparators(...comparators));
}

// run filter on sorted items
Expand Down Expand Up @@ -344,10 +341,7 @@ export class StatsFactory {
h => h.call(comparators2, context)
);
if (comparators2.length > 0) {
resultItems.sort(
// @ts-expect-error number of arguments is correct
concatComparators(...comparators2)
);
resultItems.sort(concatComparators(...comparators2));
}

// group result items
Expand Down
16 changes: 7 additions & 9 deletions packages/rspack/src/util/comparators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,18 @@ const concatComparatorsCache: TwoKeyWeakMap<
Comparator
> = new TwoKeyWeakMap();

export const concatComparators = (
c1: Comparator,
c2: Comparator,
...cRest: Comparator[]
): Comparator => {
if (cRest.length > 0) {
const [c3, ...cRest2] = cRest;
return concatComparators(c1, concatComparators(c2, c3, ...cRest2));
}
export const concatComparators = (...comps: Array<Comparator>): Comparator => {
const [c1, c2, ...cRest] = comps;

if (c2 === undefined) {
return c1;
}

if (cRest.length > 0) {
const [c3, ...cRest2] = cRest;
return concatComparators(c1, concatComparators(c2, c3, ...cRest2));
}

const cacheEntry = concatComparatorsCache.get(c1, c2);
if (cacheEntry !== undefined) return cacheEntry;

Expand Down

2 comments on commit f8d3a69

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Ran ecosystem CI: Open

suite result
modernjs ❌ failure
_selftest ✅ success
nx ❌ failure
rspress ✅ success
rsbuild ✅ success
examples ✅ success

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Benchmark detail: Open

Name Base (2024-07-31 9e2cbe9) Current Change
10000_development-mode + exec 2.27 s ± 20 ms 2.24 s ± 27 ms -1.64 %
10000_development-mode_hmr + exec 702 ms ± 11 ms 702 ms ± 12 ms +0.12 %
10000_production-mode + exec 2.76 s ± 39 ms 2.7 s ± 25 ms -2.11 %
arco-pro_development-mode + exec 1.88 s ± 66 ms 1.88 s ± 53 ms -0.18 %
arco-pro_development-mode_hmr + exec 433 ms ± 1.7 ms 434 ms ± 3.3 ms +0.33 %
arco-pro_production-mode + exec 3.45 s ± 114 ms 3.4 s ± 107 ms -1.31 %
threejs_development-mode_10x + exec 1.75 s ± 25 ms 1.76 s ± 25 ms +1.07 %
threejs_development-mode_10x_hmr + exec 863 ms ± 8.3 ms 881 ms ± 4.6 ms +2.11 %
threejs_production-mode_10x + exec 5.49 s ± 26 ms 5.49 s ± 32 ms -0.04 %

Please sign in to comment.