mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-06 06:20:55 -08:00
* lisp/isearch.el (search-within-boundaries): Optimize (bug#78520).
For non-subregexp case, search for the first match and continue from its position. This avoids unnecessary scan for all text properties until the first match. When nothing is found, skip the entire body.
This commit is contained in:
parent
6279a9e8ef
commit
295f73d23d
1 changed files with 27 additions and 14 deletions
|
|
@ -4610,9 +4610,7 @@ defaults to the value of `isearch-search-fun-default' when nil."
|
||||||
(defun search-within-boundaries ( search-fun get-fun next-fun
|
(defun search-within-boundaries ( search-fun get-fun next-fun
|
||||||
string &optional bound noerror count)
|
string &optional bound noerror count)
|
||||||
(let* ((old (point))
|
(let* ((old (point))
|
||||||
;; Check if point is already on the property.
|
beg end found skip (i 0)
|
||||||
(beg (when (funcall get-fun old) old))
|
|
||||||
end found (i 0)
|
|
||||||
(subregexp
|
(subregexp
|
||||||
(and isearch-regexp
|
(and isearch-regexp
|
||||||
(save-match-data
|
(save-match-data
|
||||||
|
|
@ -4622,18 +4620,33 @@ defaults to the value of `isearch-search-fun-default' when nil."
|
||||||
(when (subregexp-context-p string (match-beginning 0))
|
(when (subregexp-context-p string (match-beginning 0))
|
||||||
;; The ^/$ is not inside a char-range or escaped.
|
;; The ^/$ is not inside a char-range or escaped.
|
||||||
(throw 'subregexp t))))))))
|
(throw 'subregexp t))))))))
|
||||||
;; Otherwise, try to search for the next property.
|
|
||||||
(unless beg
|
;; Optimization for non-subregexp case to set the initial position
|
||||||
(setq beg (funcall next-fun old))
|
;; on the first match assuming there is no need to check boundaries
|
||||||
(when beg
|
;; for a search string/regexp without anchors (bug#78520).
|
||||||
(if (or (null bound)
|
(unless subregexp
|
||||||
(if isearch-forward
|
(save-match-data
|
||||||
(< beg bound)
|
(if (funcall (or search-fun (isearch-search-fun-default))
|
||||||
(> beg bound)))
|
string bound noerror count)
|
||||||
(goto-char beg)
|
(goto-char (if isearch-forward (match-beginning 0) (match-end 0)))
|
||||||
(setq beg nil))))
|
(setq skip t))))
|
||||||
|
|
||||||
|
(unless skip
|
||||||
|
;; Check if point is already on the property.
|
||||||
|
(setq beg (when (funcall get-fun (point)) (point)))
|
||||||
|
;; Otherwise, try to search for the next property.
|
||||||
|
(unless beg
|
||||||
|
(setq beg (funcall next-fun (point)))
|
||||||
|
(when beg
|
||||||
|
(if (or (null bound)
|
||||||
|
(if isearch-forward
|
||||||
|
(< beg bound)
|
||||||
|
(> beg bound)))
|
||||||
|
(goto-char beg)
|
||||||
|
(setq beg nil)))))
|
||||||
|
|
||||||
;; Non-nil `beg' means there are more properties.
|
;; Non-nil `beg' means there are more properties.
|
||||||
(while (and beg (not found))
|
(while (and beg (not found) (not skip))
|
||||||
;; Search for the end of the current property.
|
;; Search for the end of the current property.
|
||||||
(setq end (funcall next-fun beg))
|
(setq end (funcall next-fun beg))
|
||||||
;; Handle ^/$ specially by matching in a temporary buffer.
|
;; Handle ^/$ specially by matching in a temporary buffer.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue