Skip to content

Commit

Permalink
Fail faster in markdown-match-generic-links
Browse files Browse the repository at this point in the history
Use a preliminary regular expression search to return more quickly
upon failure.  The regular expression doesn't handle malformed links
or nested square brackets well, but if that search passes then
continue with a more precise search.
  • Loading branch information
jrblevin committed Nov 21, 2017
1 parent ffe6265 commit c9955dc
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion markdown-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -4100,7 +4100,15 @@ links with URLs."
(while (and (progn
;; Clear match data to test for a match after functions returns.
(set-match-data nil)
(re-search-forward "\\(!\\)?\\(\\[\\)" last 'limit))
;; Preliminary regular expression search so we can return
;; quickly upon failure. This doesn't handle malformed links
;; or nested square brackets well, so if it passes we back up
;; continue with a more precise search.
(re-search-forward
(if ref
markdown-regex-link-reference
markdown-regex-link-inline)
last 'limit))
;; Keep searching if this is in a code block, inline
;; code, or a comment, or if it is include syntax.
(or (markdown-code-block-at-point-p)
Expand Down

0 comments on commit c9955dc

Please sign in to comment.