mirror of
https://github.com/m00natic/vlfi.git
synced 2025-01-31 10:10:48 +00:00
Optimize search a bit.
This commit is contained in:
parent
88cf03caba
commit
670561e811
39
vlfi.el
39
vlfi.el
@ -277,17 +277,18 @@ OP-TYPE specifies the file operation being performed over FILENAME."
|
|||||||
(if backward
|
(if backward
|
||||||
(while (not (zerop to-find))
|
(while (not (zerop to-find))
|
||||||
(cond ((re-search-backward regexp nil t)
|
(cond ((re-search-backward regexp nil t)
|
||||||
(setq match-start-pos (+ vlfi-start-pos
|
(setq to-find (1- to-find)
|
||||||
(match-beginning 0)))
|
match-start-pos (+ vlfi-start-pos
|
||||||
(let ((new-match-end (+ vlfi-start-pos
|
(match-beginning 0))
|
||||||
(match-end 0))))
|
match-end-pos (+ vlfi-start-pos
|
||||||
(if (< new-match-end match-end-pos)
|
(match-end 0))))
|
||||||
(setq to-find (1- to-find)
|
|
||||||
match-end-pos new-match-end))))
|
|
||||||
((zerop vlfi-start-pos)
|
((zerop vlfi-start-pos)
|
||||||
(throw 'end-of-file nil))
|
(throw 'end-of-file nil))
|
||||||
(t (vlfi-move-to-batch (- vlfi-start-pos
|
(t (let ((half-move (- vlfi-start-pos half-batch)))
|
||||||
half-batch))
|
(vlfi-move-to-batch
|
||||||
|
(if (< match-start-pos half-move)
|
||||||
|
(- match-start-pos vlfi-batch-size)
|
||||||
|
half-move)))
|
||||||
(goto-char (if (< match-start-pos
|
(goto-char (if (< match-start-pos
|
||||||
vlfi-end-pos)
|
vlfi-end-pos)
|
||||||
(- match-start-pos
|
(- match-start-pos
|
||||||
@ -297,16 +298,18 @@ OP-TYPE specifies the file operation being performed over FILENAME."
|
|||||||
vlfi-start-pos))))
|
vlfi-start-pos))))
|
||||||
(while (not (zerop to-find))
|
(while (not (zerop to-find))
|
||||||
(cond ((re-search-forward regexp nil t)
|
(cond ((re-search-forward regexp nil t)
|
||||||
(setq match-end-pos (+ vlfi-start-pos
|
(setq to-find (1- to-find)
|
||||||
(match-end 0)))
|
match-start-pos (+ vlfi-start-pos
|
||||||
(let ((new-match-start (+ vlfi-start-pos
|
(match-beginning 0))
|
||||||
(match-beginning 0))))
|
match-end-pos (+ vlfi-start-pos
|
||||||
(if (< match-start-pos new-match-start)
|
(match-end 0))))
|
||||||
(setq to-find (1- to-find)
|
|
||||||
match-start-pos new-match-start))))
|
|
||||||
((= vlfi-end-pos vlfi-file-size)
|
((= vlfi-end-pos vlfi-file-size)
|
||||||
(throw 'end-of-file nil))
|
(throw 'end-of-file nil))
|
||||||
(t (vlfi-move-to-batch (- vlfi-end-pos half-batch))
|
(t (let ((half-move (- vlfi-end-pos half-batch)))
|
||||||
|
(vlfi-move-to-batch
|
||||||
|
(if (< half-move match-end-pos)
|
||||||
|
match-end-pos
|
||||||
|
half-move)))
|
||||||
(goto-char (if (< vlfi-start-pos match-end-pos)
|
(goto-char (if (< vlfi-start-pos match-end-pos)
|
||||||
(- match-end-pos vlfi-start-pos)
|
(- match-end-pos vlfi-start-pos)
|
||||||
(point-min)))
|
(point-min)))
|
||||||
@ -341,7 +344,7 @@ successful. Return nil if nothing found."
|
|||||||
|
|
||||||
(defun vlfi-re-search-backward (regexp count)
|
(defun vlfi-re-search-backward (regexp count)
|
||||||
"Search backward for REGEXP prefix COUNT number of times."
|
"Search backward for REGEXP prefix COUNT number of times."
|
||||||
(interactive (list (read-regexp "Search whole file"
|
(interactive (list (read-regexp "Search whole file backward"
|
||||||
(if regexp-history
|
(if regexp-history
|
||||||
(car regexp-history))
|
(car regexp-history))
|
||||||
'regexp-history)
|
'regexp-history)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user