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:
David Anson 2022-06-17 05:29:12 +00:00 committed by GitHub
parent 1f9497ad09
commit e8cdb5619c
2 changed files with 11 additions and 10 deletions

View file

@ -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];

View file

@ -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];