Skip to content

Commit

Permalink
Avoid save-match-data for efficiency
Browse files Browse the repository at this point in the history
The functions markdown-cur-line-blank-p and markdown-new-baseline-p
are called repeatedly for font lock and so efficiency is important.
We rarely care about preserving the match data when calling these
functions, so we no longer guarantee that the match data will be
preserved for performance reasons.
  • Loading branch information
jrblevin committed Feb 23, 2016
1 parent 1f98a34 commit da1cf8d
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions markdown-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -1502,7 +1502,7 @@ region to refontify."
;; If the current line has sufficient indentation, mark out pre block
;; The opening should be preceded by a blank line.
((and (looking-at pre-regexp)
(markdown-prev-line-blank-p))
(save-match-data (markdown-prev-line-blank-p)))
(setq open (match-beginning 0))
(while (and (or (looking-at pre-regexp) (markdown-cur-line-blank-p))
(not (eobp)))
Expand Down Expand Up @@ -2399,10 +2399,9 @@ in XEmacs 21."

(defun markdown-cur-line-blank-p ()
"Return t if the current line is blank and nil otherwise."
(save-match-data
(save-excursion
(beginning-of-line)
(re-search-forward "^\\s *$" (line-end-position) t))))
(save-excursion
(beginning-of-line)
(re-search-forward "^\\s *$" (line-end-position) t)))

(defun markdown-prev-line-blank-p ()
"Return t if the previous line is blank and nil otherwise.
Expand Down Expand Up @@ -2474,12 +2473,11 @@ Return nil if the current line is not the beginning of a list item."
"Determine if the current line begins a new baseline level."
(save-excursion
(beginning-of-line)
(save-match-data
(or (looking-at markdown-regex-header)
(looking-at markdown-regex-hr)
(and (null (markdown-cur-non-list-indent))
(= (markdown-cur-line-indent) 0)
(markdown-prev-line-blank-p))))))
(or (looking-at markdown-regex-header)
(looking-at markdown-regex-hr)
(and (null (markdown-cur-non-list-indent))
(= (markdown-cur-line-indent) 0)
(markdown-prev-line-blank-p)))))

(defun markdown-search-backward-baseline ()
"Search backward baseline point with no indentation and not a list item."
Expand Down

0 comments on commit da1cf8d

Please sign in to comment.