Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 16512bb

Browse filesBrowse files
committed
Reorder operations in getDescendantsByType helper for ~1% runtime reduction.
1 parent e6e799d commit 16512bb
Copy full SHA for 16512bb

File tree

Expand file treeCollapse file tree

2 files changed

+4
-6
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+4
-6
lines changed

‎demo/markdownlint-browser.js

Copy file name to clipboardExpand all lines: demo/markdownlint-browser.js
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -843,9 +843,8 @@ function getBlockQuotePrefixText(tokens, lineNumber, count = 1) {
843843
function getDescendantsByType(parent, typePath) {
844844
let tokens = Array.isArray(parent) ? parent : [ parent ];
845845
for (const type of typePath) {
846-
tokens = tokens
847-
.flatMap((t) => t.children)
848-
.filter((t) => Array.isArray(type) ? type.includes(t.type) : (type === t.type));
846+
const predicate = (token) => Array.isArray(type) ? type.includes(token.type) : (type === token.type);
847+
tokens = tokens.flatMap((t) => t.children.filter(predicate));
849848
}
850849
return tokens;
851850
}

‎helpers/micromark-helpers.cjs

Copy file name to clipboardExpand all lines: helpers/micromark-helpers.cjs
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,8 @@ function getBlockQuotePrefixText(tokens, lineNumber, count = 1) {
161161
function getDescendantsByType(parent, typePath) {
162162
let tokens = Array.isArray(parent) ? parent : [ parent ];
163163
for (const type of typePath) {
164-
tokens = tokens
165-
.flatMap((t) => t.children)
166-
.filter((t) => Array.isArray(type) ? type.includes(t.type) : (type === t.type));
164+
const predicate = (token) => Array.isArray(type) ? type.includes(token.type) : (type === token.type);
165+
tokens = tokens.flatMap((t) => t.children.filter(predicate));
167166
}
168167
return tokens;
169168
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.