Reorder checks in filterByTypes helper predicate for ~2% runtime reduction.

This commit is contained in:
David Anson 2024-10-23 21:44:36 -07:00
parent d94b78e6bf
commit e6e799d145
2 changed files with 2 additions and 4 deletions

View file

@ -806,8 +806,7 @@ function filterByPredicate(tokens, allowed, transformChildren) {
* @returns {Token[]} Filtered tokens.
*/
function filterByTypes(tokens, types, htmlFlow) {
const predicate = (token) =>
(htmlFlow || !inHtmlFlow(token)) && types.includes(token.type);
const predicate = (token) => types.includes(token.type) && (htmlFlow || !inHtmlFlow(token));
const flatTokens = tokens[flatTokensSymbol];
if (flatTokens) {
return flatTokens.filter(predicate);