feat(tl): generate switches instead of OR expressions
switches are WAY faster.
This commit is contained in:
parent
f19fdf76b8
commit
6879ae945a
1 changed files with 5 additions and 3 deletions
|
@ -226,9 +226,11 @@ const writeSingleSchemaEntry = (type) => {
|
||||||
js.write(`${jsPrefix}isAny${camelToPascal(
|
js.write(`${jsPrefix}isAny${camelToPascal(
|
||||||
union.type
|
union.type
|
||||||
)} = function (obj) {
|
)} = function (obj) {
|
||||||
return ${union.subtypes
|
switch (obj._) {
|
||||||
.map((typ) => `obj._ === '${prefix_}${typ}'`)
|
${union.subtypes
|
||||||
.join(' || ')};
|
.map((typ) => `case '${prefix_}${typ}':`).join('')}return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
};`)
|
};`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue