mirror of
https://github.com/m00natic/vlfi.git
synced 2025-01-18 20:10:47 +00:00
Optimize vlf-goto-line not to decode batches as long as possible.
This commit is contained in:
parent
0fa8e8d6bf
commit
5c604c48a4
@ -175,22 +175,53 @@ Search is performed chunk by chunk in `vlf-batch-size' memory."
|
|||||||
"Go to line N. If N is negative, count from the end of file."
|
"Go to line N. If N is negative, count from the end of file."
|
||||||
(interactive (if (vlf-no-modifications)
|
(interactive (if (vlf-no-modifications)
|
||||||
(list (read-number "Go to line: "))))
|
(list (read-number "Go to line: "))))
|
||||||
|
(vlf-verify-size)
|
||||||
(let ((start-pos vlf-start-pos)
|
(let ((start-pos vlf-start-pos)
|
||||||
(end-pos vlf-end-pos)
|
(end-pos vlf-end-pos)
|
||||||
(pos (point))
|
(pos (point))
|
||||||
(success nil))
|
(success nil))
|
||||||
(unwind-protect
|
(unwind-protect
|
||||||
(if (< 0 n)
|
(if (< 0 n)
|
||||||
(progn (vlf-beginning-of-file)
|
(let ((start 0)
|
||||||
(goto-char (point-min))
|
(end (min vlf-batch-size vlf-file-size))
|
||||||
(setq success (vlf-re-search "[\n\C-m]" (1- n)
|
(inhibit-read-only t))
|
||||||
nil 0)))
|
(setq n (1- n))
|
||||||
(vlf-end-of-file)
|
(vlf-with-undo-disabled
|
||||||
(goto-char (point-max))
|
(while (and (< (- end start) n)
|
||||||
(setq success (vlf-re-search "[\n\C-m]" (- n) t 0)))
|
(< n (- vlf-file-size start)))
|
||||||
(if success
|
(erase-buffer)
|
||||||
(message "Onto line %s" n)
|
(insert-file-contents-literally buffer-file-name
|
||||||
(vlf-move-to-chunk start-pos end-pos)
|
nil start end)
|
||||||
|
(goto-char (point-min))
|
||||||
|
(while (re-search-forward "[\n\C-m]" nil t)
|
||||||
|
(setq n (1- n)))
|
||||||
|
(vlf-verify-size)
|
||||||
|
(setq start end
|
||||||
|
end (min vlf-file-size
|
||||||
|
(+ start vlf-batch-size))))
|
||||||
|
(when (< n (- vlf-file-size end))
|
||||||
|
(vlf-move-to-chunk-2 start end)
|
||||||
|
(goto-char (point-min))
|
||||||
|
(setq success (vlf-re-search "[\n\C-m]" n nil 0)))))
|
||||||
|
(let ((start (max 0 (- vlf-file-size vlf-batch-size)))
|
||||||
|
(end vlf-file-size)
|
||||||
|
(inhibit-read-only t))
|
||||||
|
(vlf-with-undo-disabled
|
||||||
|
(while (and (< (- end) n) (< n (- start end)))
|
||||||
|
(erase-buffer)
|
||||||
|
(insert-file-contents-literally buffer-file-name nil
|
||||||
|
start end)
|
||||||
|
(goto-char (point-max))
|
||||||
|
(while (re-search-backward "[\n\C-m]" nil t)
|
||||||
|
(setq n (1+ n)))
|
||||||
|
(setq end start
|
||||||
|
start (max 0 (- end vlf-batch-size))))
|
||||||
|
(when (< (- end) n)
|
||||||
|
(vlf-move-to-chunk-2 start end)
|
||||||
|
(goto-char (point-max))
|
||||||
|
(setq success (vlf-re-search "[\n\C-m]" (- n) t 0))))))
|
||||||
|
(unless success
|
||||||
|
(vlf-move-to-chunk-2 start-pos end-pos)
|
||||||
(goto-char pos)))))
|
(goto-char pos)))))
|
||||||
|
|
||||||
(provide 'vlf-search)
|
(provide 'vlf-search)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user