Skip to content

Commit 0098856

Browse files
🚴 perf(sortTyped): Go to optimized loop after first iteration.
1 parent c6592a9 commit 0098856

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/sortTypedDecreasing.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
import sortTypedDecreasingOptimized from './sortTypedDecreasingOptimized.js';
2+
13
const sortTypedDecreasing = (a, i, j) => {
2-
for (let k = i + 1; k < j; ++k) {
4+
const k = i + 1;
5+
if (k < j) {
36
let t = k;
47
const o = a[t];
58
while (t-- > i && a[t] < o) a[t + 1] = a[t];
69
a[t + 1] = o;
10+
sortTypedDecreasingOptimized(a, k, j);
711
}
812
};
913

src/sortTypedIncreasing.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
import sortTypedIncreasingOptimized from './sortTypedIncreasingOptimized.js';
2+
13
const sortTypedIncreasing = (a, i, j) => {
2-
for (let k = i + 1; k < j; ++k) {
4+
const k = i + 1;
5+
if (k < j) {
36
let t = k;
47
const o = a[t];
58
while (t-- > i && a[t] > o) a[t + 1] = a[t];
69
a[t + 1] = o;
10+
sortTypedIncreasingOptimized(a, k, j);
711
}
812
};
913

0 commit comments

Comments
 (0)