Skip to content

Commit

Permalink
🚀 perf(_from_small_list): Replace throw by optional assert.
Browse files Browse the repository at this point in the history
  • Loading branch information
make-github-pseudonymous-again committed Dec 23, 2020
1 parent 5ce530d commit 921ed98
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/0-core/_fast/_from_small_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import {Empty, Single, Deep} from '../../3-tree';
import {One, Two} from '../../1-digit';
import {cache} from '../measure';

import assert from 'assert';

export function _from_small_list(M, list) {
assert(Number.isInteger(list.length) && list.length >= 0 && list.length <= 3);
switch (list.length) {
case 0:
return new Empty(M);
Expand All @@ -15,14 +18,12 @@ export function _from_small_list(M, list) {
new Empty(cache(M)),
new One(list[1])
);
case 3:
default:
return new Deep(
M,
new Two(list[0], list[1]),
new Empty(cache(M)),
new One(list[2])
);
default:
throw new Error('second argument has wrong length');
}
}

0 comments on commit 921ed98

Please sign in to comment.