Update helpers.forEachInlineCodeSpan to remove backtick detection in link destinations for ~22% time reduction measured via profile-fixture.mjs on GitHub Codespaces.

This commit is contained in:
David Anson 2022-06-19 00:49:36 +00:00 committed by GitHub
parent e8cdb5619c
commit d177ee2fc5
2 changed files with 2 additions and 32 deletions

View file

@ -446,28 +446,12 @@ function forEachInlineCodeSpan(input, handler) {
let startColumn = -1;
let tickCount = 0;
let currentTicks = 0;
let state = "normal";
// Deliberate <= so trailing 0 completes the last span (ex: "text `code`")
// False-positive for js/index-out-of-bounds
for (; index <= input.length; index++) {
const char = input[index];
// Ignore backticks in link destination
if ((char === "[") && (state === "normal")) {
state = "linkTextOpen";
}
else if ((char === "]") && (state === "linkTextOpen")) {
state = "linkTextClosed";
}
else if ((char === "(") && (state === "linkTextClosed")) {
state = "linkDestinationOpen";
}
else if (((char === "(") && (state === "linkDestinationOpen")) ||
((char === ")") && (state === "linkDestinationOpen")) ||
(state === "linkTextClosed")) {
state = "normal";
}
// Parse backtick open/close
if ((char === "`") && (state !== "linkDestinationOpen")) {
if (char === "`") {
// Count backticks at start or end of code span
currentTicks++;
if ((startIndex === -1) || (startColumn === -1)) {