Repository navigation
fix: find image placeholders in linear time - #44
Merged
Merged
Conversation
The placeholder pattern retried every "![" and was quadratic on a document without a closing "]". A forward scan returns the same matches; the test keeps the pattern as the oracle over generated documents. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
Author
|
CODEX VERDICT: LGTM Read SHA: 1cde03c.
Checks run: yarn test (18/18 passed), yarn typecheck, yarn lint, yarn build. Lint has only the existing six warnings outside this change's new code. Additional random comparison against the old regex passed for 100,000 inputs. The seeded oracle corpus exercised 65 matching documents and 65 matches. No mutation sweep was run. FINDINGS COMPLETE: I read every hunk of the diff and this is every finding I have. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #43.
/!\[([^\]]+)\]\(\/?__too_be_replaced_image_path__\)/gretried every![and scanned to the end each time. Amarkdownargument with many![and no]therefore took quadratic time and blocked the event loop. CodeQL reports this asjs/polynomial-redos(alerts 2 and 3).src/core/imagePlaceholders.tshas two functions:findImagePlaceholdersreturns the same matches with one forward scan. A prompt holds no], so the only candidate ending at a given]starts at the first![after the previous].replaceImagePlaceholdersrebuilds the document from those matches.plugin.tsnow replaces from the matches it already found, instead of matching a second time.Items to Confirm
tests/imagePlaceholders.test.ts. On seeded generated documents built from!,[,], the placeholder targets and near-misses, both the matches and the replaced document must equal the pattern's.BUDGET_MS). At a fifth of the test's input length, the old pattern took seconds.src/core/plugin.ts, and so does chore: prettier を入れて整形をそろえる (2026-10-18) #41 (Prettier), so whichever lands second needsmainmerged in. The CodeQL failure on chore: prettier を入れて整形をそろえる (2026-10-18) #41 is these same two alerts, counted as new there because chore: prettier を入れて整形をそろえる (2026-10-18) #41 reformats the lines. It should clear once this is onmain.Verification
yarn lint,yarn build,yarn typecheckandyarn testpass (noformatscript onmainyet).![, the prompt start and the tail copy each turn the tests red. Resuming atclose + 1instead of the match end is equivalent, because the targets hold no]or![.User Prompt
🤖 Generated with Claude Code
work in GUIChatPluginSpreadsheet