Skip to content

Commit 921ed98

Browse files
🚀 perf(_from_small_list): Replace throw by optional assert.
1 parent 5ce530d commit 921ed98

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/0-core/_fast/_from_small_list.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import {Empty, Single, Deep} from '../../3-tree';
22
import {One, Two} from '../../1-digit';
33
import {cache} from '../measure';
44

5+
import assert from 'assert';
6+
57
export function _from_small_list(M, list) {
8+
assert(Number.isInteger(list.length) && list.length >= 0 && list.length <= 3);
69
switch (list.length) {
710
case 0:
811
return new Empty(M);
@@ -15,14 +18,12 @@ export function _from_small_list(M, list) {
1518
new Empty(cache(M)),
1619
new One(list[1])
1720
);
18-
case 3:
21+
default:
1922
return new Deep(
2023
M,
2124
new Two(list[0], list[1]),
2225
new Empty(cache(M)),
2326
new One(list[2])
2427
);
25-
default:
26-
throw new Error('second argument has wrong length');
2728
}
2829
}

0 commit comments

Comments
 (0)