diff --git a/CHANGES.md b/CHANGES.md index 724417a3..64e1c5aa 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -13,6 +13,7 @@ - `markdown-preview` displays the buffer name as the page title - skip export tests if export command is not installed - reduce memory allocations in property checking functions + - improve performance to check properties in range by using c functions [gh-937]: https://github.com/jrblevin/markdown-mode/pull/937 diff --git a/markdown-mode.el b/markdown-mode.el index 00a57f16..87be51a2 100644 --- a/markdown-mode.el +++ b/markdown-mode.el @@ -2931,19 +2931,16 @@ This may be useful for tables and Pandoc's line_blocks extension." Also returns t if PROP is a list containing one of the PROP-VALUES. Return nil otherwise." (catch 'found - (cl-loop - with props = nil - for loc from begin to end - do - (when (setq props (get-text-property loc prop)) - (cond ((listp props) + (let ((loc begin)) + (while (<= loc end) + (when-let* ((props (get-text-property loc prop))) + (if (listp props) ;; props is a list, check for membership (dolist (val prop-values) - (when (memq val props) (throw 'found loc)))) - (t - ;; props is a scalar, check for equality - (dolist (val prop-values) - (when (eq val props) (throw 'found loc))))))))) + (when (memq val props) (throw 'found loc))) + (dolist (val prop-values) + (when (eq val props) (throw 'found loc))))) + (setq loc (next-single-property-change loc prop nil (1+ end))))))) (defun markdown-range-properties-exist (begin end props) (cl-loop