Skip to content

Commit fcd68c7

Browse files
🚀 perf(_from_digit): Replace throw by optional assert.
1 parent f56b5d4 commit fcd68c7

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

src/0-core/_fast/_from_digit.js

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

5+
import assert from 'assert';
6+
57
export function _from_digit(M, digit) {
68
if (digit instanceof One) return new Single(M, digit.a);
7-
if (digit instanceof Two || digit instanceof Three || digit instanceof Four) {
8-
return new Deep(
9-
M,
10-
digit.init(),
11-
new Empty(cache(M)),
12-
new One(digit.last())
13-
);
14-
}
15-
16-
// Potential optimization by commenting out this section
17-
// and remove the second test above
18-
throw new Error('second argument is not a Digit');
9+
assert(
10+
digit instanceof Two || digit instanceof Three || digit instanceof Four
11+
);
12+
return new Deep(M, digit.init(), new Empty(cache(M)), new One(digit.last()));
1913
}

0 commit comments

Comments
 (0)