1
0
mirror of https://github.com/m00natic/vlfi.git synced 2024-10-05 18:30:51 +01:00

Apply and restore batch size in more cases.

This commit is contained in:
Andrey Kotlarski 2014-09-07 16:25:36 +03:00
parent 9271f68c05
commit d526ea8ef8
4 changed files with 51 additions and 43 deletions

View File

@ -161,28 +161,31 @@ Prematurely ending indexing will still show what's found so far."
buffer-undo-list t) buffer-undo-list t)
(set-buffer-modified-p nil) (set-buffer-modified-p nil)
(set (make-local-variable 'vlf-batch-size) batch-size) (set (make-local-variable 'vlf-batch-size) batch-size)
(setq vlf-tune-insert-bps insert-bps (when vlf-tune-enabled
vlf-tune-encode-bps encode-bps) (setq vlf-tune-insert-bps insert-bps
(if is-hexl vlf-tune-encode-bps encode-bps)
(progn (setq vlf-tune-hexl-bps hexl-bps (if is-hexl
vlf-tune-dehexlify-bps dehexlify-bps) (progn (setq vlf-tune-hexl-bps hexl-bps
(vlf-tune-batch '(:hexl :dehexlify :insert :encode))) vlf-tune-dehexlify-bps dehexlify-bps)
(vlf-tune-batch '(:insert :encode))) (vlf-tune-batch '(:hexl :dehexlify :insert :encode)))
(vlf-tune-batch '(:insert :encode))))
(vlf-mode 1) (vlf-mode 1)
(if is-hexl (vlf-tune-hexlify)) (if is-hexl (vlf-tune-hexlify))
(goto-char (point-min)) (goto-char (point-min))
(vlf-with-undo-disabled (vlf-with-undo-disabled
(vlf-build-occur regexp vlf-buffer)) (vlf-build-occur regexp vlf-buffer))
(setq insert-bps vlf-tune-insert-bps (when vlf-tune-enabled
encode-bps vlf-tune-encode-bps) (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))))
(when vlf-tune-enabled ;merge back tune measurements
(setq vlf-tune-insert-bps insert-bps
vlf-tune-encode-bps encode-bps)
(if is-hexl (if is-hexl
(setq insert-bps vlf-tune-insert-bps (setq vlf-tune-insert-bps insert-bps
encode-bps vlf-tune-encode-bps))) vlf-tune-encode-bps 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.
@ -196,16 +199,18 @@ Prematurely ending indexing will still show what's found so far."
(vlf-occur-other-buffer regexp) (vlf-occur-other-buffer regexp)
(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) (batch-size vlf-batch-size))
(vlf-tune-batch '(:hexl :dehexlify :insert :encode)) (vlf-tune-batch (if (derived-mode-p 'hexl-mode)
(vlf-tune-batch '(:insert :encode))) '(:hexl :dehexlify :insert :encode)
'(:insert :encode)))
(vlf-with-undo-disabled (vlf-with-undo-disabled
(vlf-move-to-batch 0) (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)))
(setq vlf-batch-size batch-size)))
(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)

View File

@ -234,10 +234,9 @@ 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))
(if is-hexl (vlf-tune-batch (if is-hexl
(vlf-tune-batch '(:hexl :dehexlify '(:hexl :dehexlify :insert :encode)
:insert :encode)) '(:insert :encode)))
(vlf-tune-batch '(:insert :encode)))
(vlf-move-to-chunk-2 start (+ start vlf-batch-size)) (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
@ -264,10 +263,9 @@ 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)
(if is-hexl (vlf-tune-batch (if is-hexl
(vlf-tune-batch '(:hexl :dehexlify '(:hexl :dehexlify :insert :encode)
:insert :encode)) '(:insert :encode)))
(vlf-tune-batch '(:insert :encode)))
(vlf-move-to-chunk-2 (- end vlf-batch-size) end) (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

View File

@ -213,8 +213,10 @@ unless DONT-APPROXIMATE is t."
`(aset ,vec ,index 0) `(aset ,vec ,index 0)
`(vlf-tune-approximate-nearby ,vec ,index))) `(vlf-tune-approximate-nearby ,vec ,index)))
((zerop val) ;index has been tried before, yet still no value ((zerop val) ;index has been tried before, yet still no value
(aset ,vec ,index ,(if dont-approximate
(vlf-tune-approximate-nearby ,vec ,index))) `(aset ,vec ,index
(vlf-tune-approximate-nearby ,vec ,index))
`(vlf-tune-approximate-nearby ,vec ,index)))
(t val))))) (t val)))))
(defmacro vlf-tune-get-vector (key) (defmacro vlf-tune-get-vector (key)

27
vlf.el
View File

@ -172,9 +172,9 @@ When prefix argument is negative
append next APPEND number of batches to the existing buffer." append next APPEND number of batches to the existing buffer."
(interactive "p") (interactive "p")
(vlf-verify-size) (vlf-verify-size)
(if (derived-mode-p 'hexl-mode) (vlf-tune-conservative (if (derived-mode-p 'hexl-mode)
(vlf-tune-conservative '(:hexl :dehexlify :insert :encode)) '(:hexl :dehexlify :insert :encode)
(vlf-tune-conservative '(:insert :encode))) '(:insert :encode)))
(let* ((end (min (+ vlf-end-pos (* vlf-batch-size (abs append))) (let* ((end (min (+ vlf-end-pos (* vlf-batch-size (abs append)))
vlf-file-size)) vlf-file-size))
(start (if (< append 0) (start (if (< append 0)
@ -191,9 +191,9 @@ When prefix argument is negative
(interactive "p") (interactive "p")
(if (zerop vlf-start-pos) (if (zerop vlf-start-pos)
(error "Already at BOF")) (error "Already at BOF"))
(if (derived-mode-p 'hexl-mode) (vlf-tune-conservative (if (derived-mode-p 'hexl-mode)
(vlf-tune-conservative '(:hexl :dehexlify :insert :encode)) '(:hexl :dehexlify :insert :encode)
(vlf-tune-conservative '(:insert :encode))) '(:insert :encode)))
(let* ((start (max 0 (- vlf-start-pos (* vlf-batch-size (abs prepend))))) (let* ((start (max 0 (- vlf-start-pos (* vlf-batch-size (abs prepend)))))
(end (if (< prepend 0) (end (if (< prepend 0)
vlf-end-pos vlf-end-pos
@ -271,18 +271,18 @@ with the prefix argument DECREASE it is halved."
(defun vlf-beginning-of-file () (defun vlf-beginning-of-file ()
"Jump to beginning of file content." "Jump to beginning of file content."
(interactive) (interactive)
(if (derived-mode-p 'hexl-mode) (vlf-tune-conservative (if (derived-mode-p 'hexl-mode)
(vlf-tune-conservative '(:hexl :dehexlify :insert :encode)) '(:hexl :dehexlify :insert :encode)
(vlf-tune-conservative '(:insert :encode))) '(:insert :encode)))
(vlf-move-to-batch 0)) (vlf-move-to-batch 0))
(defun vlf-end-of-file () (defun vlf-end-of-file ()
"Jump to end of file content." "Jump to end of file content."
(interactive) (interactive)
(vlf-verify-size) (vlf-verify-size)
(if (derived-mode-p 'hexl-mode) (vlf-tune-conservative (if (derived-mode-p 'hexl-mode)
(vlf-tune-conservative '(:hexl :dehexlify :insert :encode)) '(:hexl :dehexlify :insert :encode)
(vlf-tune-conservative '(:insert :encode))) '(:insert :encode)))
(vlf-move-to-batch vlf-file-size)) (vlf-move-to-batch vlf-file-size))
(defun vlf-revert (&optional _auto noconfirm) (defun vlf-revert (&optional _auto noconfirm)
@ -298,6 +298,9 @@ Ask for confirmation if NOCONFIRM is nil."
(defun vlf-jump-to-chunk (n) (defun vlf-jump-to-chunk (n)
"Go to to chunk N." "Go to to chunk N."
(interactive "nGoto to chunk: ") (interactive "nGoto to chunk: ")
(vlf-tune-conservative (if (derived-mode-p 'hexl-mode)
'(:hexl :dehexlify :insert :encode)
'(:insert :encode)))
(vlf-move-to-batch (* (1- n) vlf-batch-size))) (vlf-move-to-batch (* (1- n) vlf-batch-size)))
(defun vlf-no-modifications () (defun vlf-no-modifications ()