mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Reorder operations in getDescendantsByType helper for ~1% runtime reduction.
This commit is contained in:
parent
e6e799d145
commit
16512bba25
2 changed files with 4 additions and 6 deletions
|
@ -843,9 +843,8 @@ function getBlockQuotePrefixText(tokens, lineNumber, count = 1) {
|
|||
function getDescendantsByType(parent, typePath) {
|
||||
let tokens = Array.isArray(parent) ? parent : [ parent ];
|
||||
for (const type of typePath) {
|
||||
tokens = tokens
|
||||
.flatMap((t) => t.children)
|
||||
.filter((t) => Array.isArray(type) ? type.includes(t.type) : (type === t.type));
|
||||
const predicate = (token) => Array.isArray(type) ? type.includes(token.type) : (type === token.type);
|
||||
tokens = tokens.flatMap((t) => t.children.filter(predicate));
|
||||
}
|
||||
return tokens;
|
||||
}
|
||||
|
|
|
@ -161,9 +161,8 @@ function getBlockQuotePrefixText(tokens, lineNumber, count = 1) {
|
|||
function getDescendantsByType(parent, typePath) {
|
||||
let tokens = Array.isArray(parent) ? parent : [ parent ];
|
||||
for (const type of typePath) {
|
||||
tokens = tokens
|
||||
.flatMap((t) => t.children)
|
||||
.filter((t) => Array.isArray(type) ? type.includes(t.type) : (type === t.type));
|
||||
const predicate = (token) => Array.isArray(type) ? type.includes(token.type) : (type === token.type);
|
||||
tokens = tokens.flatMap((t) => t.children.filter(predicate));
|
||||
}
|
||||
return tokens;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue