mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Update token annotation to call helpers.forEachInlineCodeSpan only when necessary for ~11% time reduction measured via profile-fixture.mjs on GitHub Codespaces.
This commit is contained in:
parent
1f9497ad09
commit
e8cdb5619c
2 changed files with 11 additions and 10 deletions
|
|
@ -1479,11 +1479,13 @@ function annotateAndFreezeTokens(tokens, lines) {
|
|||
}
|
||||
// Annotate children with lineNumber
|
||||
if (token.children) {
|
||||
let lineNumber = token.lineNumber;
|
||||
const codeSpanExtraLines = [];
|
||||
helpers.forEachInlineCodeSpan(token.content, function handleInlineCodeSpan(code) {
|
||||
codeSpanExtraLines.push(code.split(helpers.newLineRe).length - 1);
|
||||
});
|
||||
if (token.children.some((child) => child.type === "code_inline")) {
|
||||
helpers.forEachInlineCodeSpan(token.content, (code) => {
|
||||
codeSpanExtraLines.push(code.split(helpers.newLineRe).length - 1);
|
||||
});
|
||||
}
|
||||
let lineNumber = token.lineNumber;
|
||||
for (const child of token.children) {
|
||||
child.lineNumber = lineNumber;
|
||||
child.line = lines[lineNumber - 1];
|
||||
|
|
|
|||
|
|
@ -249,14 +249,13 @@ function annotateAndFreezeTokens(tokens, lines) {
|
|||
}
|
||||
// Annotate children with lineNumber
|
||||
if (token.children) {
|
||||
let lineNumber = token.lineNumber;
|
||||
const codeSpanExtraLines = [];
|
||||
helpers.forEachInlineCodeSpan(
|
||||
token.content,
|
||||
function handleInlineCodeSpan(code) {
|
||||
if (token.children.some((child) => child.type === "code_inline")) {
|
||||
helpers.forEachInlineCodeSpan(token.content, (code) => {
|
||||
codeSpanExtraLines.push(code.split(helpers.newLineRe).length - 1);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
let lineNumber = token.lineNumber;
|
||||
for (const child of token.children) {
|
||||
child.lineNumber = lineNumber;
|
||||
child.line = lines[lineNumber - 1];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue