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
|
||||
string &optional bound noerror count)
|
||||
(let* ((old (point))
|
||||
;; Check if point is already on the property.
|
||||
(beg (when (funcall get-fun old) old))
|
||||
end found (i 0)
|
||||
beg end found skip (i 0)
|
||||
(subregexp
|
||||
(and isearch-regexp
|
||||
(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))
|
||||
;; The ^/$ is not inside a char-range or escaped.
|
||||
(throw 'subregexp t))))))))
|
||||
;; Otherwise, try to search for the next property.
|
||||
(unless beg
|
||||
(setq beg (funcall next-fun old))
|
||||
(when beg
|
||||
(if (or (null bound)
|
||||
(if isearch-forward
|
||||
(< beg bound)
|
||||
(> beg bound)))
|
||||
(goto-char beg)
|
||||
(setq beg nil))))
|
||||
|
||||
;; Optimization for non-subregexp case to set the initial position
|
||||
;; on the first match assuming there is no need to check boundaries
|
||||
;; for a search string/regexp without anchors (bug#78520).
|
||||
(unless subregexp
|
||||
(save-match-data
|
||||
(if (funcall (or search-fun (isearch-search-fun-default))
|
||||
string bound noerror count)
|
||||
(goto-char (if isearch-forward (match-beginning 0) (match-end 0)))
|
||||
(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.
|
||||
(while (and beg (not found))
|
||||
(while (and beg (not found) (not skip))
|
||||
;; Search for the end of the current property.
|
||||
(setq end (funcall next-fun beg))
|
||||
;; Handle ^/$ specially by matching in a temporary buffer.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue