1
0
mirror of https://github.com/m00natic/vlfi.git synced 2025-01-18 20:10:47 +00:00

Tune batch size in more cases.

This commit is contained in:
Andrey Kotlarski 2014-09-07 00:06:10 +03:00
parent 11c7af4b04
commit ee7409bfa5
2 changed files with 60 additions and 24 deletions

View File

@ -144,41 +144,69 @@ EVENT may hold details of the invocation."
(vlf-move-to-chunk chunk-start chunk-end) (vlf-move-to-chunk chunk-start chunk-end)
(goto-char match-pos))))) (goto-char match-pos)))))
(defun vlf-occur-other-buffer (regexp)
"Make whole file occur style index for REGEXP branching to new buffer.
Prematurely ending indexing will still show what's found so far."
(let ((vlf-buffer (current-buffer))
(file buffer-file-name)
(batch-size vlf-batch-size)
(is-hexl (derived-mode-p 'hexl-mode))
(insert-bps vlf-tune-insert-bps)
(encode-bps vlf-tune-encode-bps)
(hexl-bps vlf-tune-hexl-bps)
(dehexlify-bps vlf-tune-dehexlify-bps))
(with-temp-buffer
(setq buffer-file-name file
buffer-file-truename file
buffer-undo-list t)
(set-buffer-modified-p nil)
(set (make-local-variable 'vlf-batch-size) batch-size)
(setq vlf-tune-insert-bps insert-bps
vlf-tune-encode-bps encode-bps)
(if is-hexl
(progn (setq vlf-tune-hexl-bps hexl-bps
vlf-tune-dehexlify-bps dehexlify-bps)
(vlf-tune-batch '(:hexl :dehexlify :insert :encode)))
(vlf-tune-batch '(:insert :encode)))
(vlf-mode 1)
(if is-hexl (vlf-tune-hexlify))
(goto-char (point-min))
(vlf-with-undo-disabled
(vlf-build-occur regexp vlf-buffer))
(setq insert-bps vlf-tune-insert-bps
encode-bps vlf-tune-encode-bps)
(if is-hexl
(setq insert-bps vlf-tune-insert-bps
encode-bps vlf-tune-encode-bps)))
(setq vlf-tune-insert-bps insert-bps
vlf-tune-encode-bps encode-bps)
(if is-hexl
(setq vlf-tune-insert-bps insert-bps
vlf-tune-encode-bps encode-bps))))
(defun vlf-occur (regexp) (defun vlf-occur (regexp)
"Make whole file occur style index for REGEXP. "Make whole file occur style index for REGEXP.
Prematurely ending indexing will still show what's found so far." Prematurely ending indexing will still show what's found so far."
(interactive (list (read-regexp "List lines matching regexp" (interactive (list (read-regexp "List lines matching regexp"
(if regexp-history (if regexp-history
(car regexp-history))))) (car regexp-history)))))
(if (buffer-modified-p) ;use temporary buffer not to interfere with modifications (run-hook-with-args 'vlf-before-batch-functions 'occur)
(let ((vlf-buffer (current-buffer)) (if (or (buffer-modified-p)
(file buffer-file-name) (< vlf-batch-size vlf-start-pos))
(batch-size vlf-batch-size) (vlf-occur-other-buffer regexp)
(is-hexl (derived-mode-p 'hexl-mode)))
(with-temp-buffer
(setq buffer-file-name file
buffer-file-truename file
buffer-undo-list t)
(set-buffer-modified-p nil)
(set (make-local-variable 'vlf-batch-size) batch-size)
(vlf-mode 1)
(if is-hexl (vlf-tune-hexlify))
(run-hook-with-args 'vlf-before-batch-functions 'occur)
(goto-char (point-min))
(vlf-with-undo-disabled
(vlf-build-occur regexp vlf-buffer))
(run-hook-with-args 'vlf-after-batch-functions 'occur)))
(run-hook-with-args 'vlf-before-batch-functions 'occur)
(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)))
(if (derived-mode-p 'hexl-mode)
(vlf-tune-batch '(:hexl :dehexlify :insert :encode))
(vlf-tune-batch '(:insert :encode)))
(vlf-with-undo-disabled (vlf-with-undo-disabled
(vlf-beginning-of-file) (vlf-move-to-batch 0)
(goto-char (point-min)) (goto-char (point-min))
(unwind-protect (vlf-build-occur regexp (current-buffer)) (unwind-protect (vlf-build-occur regexp (current-buffer))
(vlf-move-to-chunk start-pos end-pos) (vlf-move-to-chunk start-pos end-pos)
(goto-char pos)))) (goto-char pos)))))
(run-hook-with-args 'vlf-after-batch-functions 'occur))) (run-hook-with-args 'vlf-after-batch-functions 'occur))
(defun vlf-build-occur (regexp vlf-buffer) (defun vlf-build-occur (regexp vlf-buffer)
"Build occur style index for REGEXP over VLF-BUFFER." "Build occur style index for REGEXP over VLF-BUFFER."

View File

@ -234,7 +234,11 @@ Search is performed chunk by chunk in `vlf-batch-size' memory."
(+ start vlf-batch-size))) (+ start vlf-batch-size)))
(progress-reporter-update reporter start))) (progress-reporter-update reporter start)))
(when (< n (- vlf-file-size end)) (when (< n (- vlf-file-size end))
(vlf-move-to-chunk-2 start end) (if is-hexl
(vlf-tune-batch '(:hexl :dehexlify
:insert :encode))
(vlf-tune-batch '(:insert :encode)))
(vlf-move-to-chunk-2 start (+ start vlf-batch-size))
(goto-char (point-min)) (goto-char (point-min))
(setq success (vlf-re-search "[\n\C-m]" n nil 0 (setq success (vlf-re-search "[\n\C-m]" n nil 0
reporter time))))) reporter time)))))
@ -260,7 +264,11 @@ Search is performed chunk by chunk in `vlf-batch-size' memory."
(progress-reporter-update reporter (progress-reporter-update reporter
(- vlf-file-size end)))) (- vlf-file-size end))))
(when (< n end) (when (< n end)
(vlf-move-to-chunk-2 start end) (if is-hexl
(vlf-tune-batch '(:hexl :dehexlify
:insert :encode))
(vlf-tune-batch '(:insert :encode)))
(vlf-move-to-chunk-2 (- end vlf-batch-size) end)
(goto-char (point-max)) (goto-char (point-max))
(setq success (vlf-re-search "[\n\C-m]" n t 0 (setq success (vlf-re-search "[\n\C-m]" n t 0
reporter time)))))) reporter time))))))