feat(tl): generate switches instead of OR expressions

switches are WAY faster.
This commit is contained in:
teidesu 2021-05-11 23:27:09 +03:00
parent f19fdf76b8
commit 6879ae945a

View file

@ -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;
};`) };`)
}) })