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)
(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)))
(when vlf-tune-enabled
(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)
(when vlf-tune-enabled
(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
(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))))
(setq vlf-tune-insert-bps insert-bps
vlf-tune-encode-bps encode-bps)))))
(defun vlf-occur (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)
(let ((start-pos vlf-start-pos)
(end-pos vlf-end-pos)
(pos (point)))
(if (derived-mode-p 'hexl-mode)
(vlf-tune-batch '(:hexl :dehexlify :insert :encode))
(vlf-tune-batch '(:insert :encode)))
(pos (point))
(batch-size vlf-batch-size))
(vlf-tune-batch (if (derived-mode-p 'hexl-mode)
'(:hexl :dehexlify :insert :encode)
'(:insert :encode)))
(vlf-with-undo-disabled
(vlf-move-to-batch 0)
(goto-char (point-min))
(unwind-protect (vlf-build-occur regexp (current-buffer))
(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))
(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)))
(progress-reporter-update reporter start)))
(when (< n (- vlf-file-size end))
(if is-hexl
(vlf-tune-batch '(:hexl :dehexlify
:insert :encode))
(vlf-tune-batch '(:insert :encode)))
(vlf-tune-batch (if is-hexl
'(:hexl :dehexlify :insert :encode)
'(:insert :encode)))
(vlf-move-to-chunk-2 start (+ start vlf-batch-size))
(goto-char (point-min))
(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
(- vlf-file-size end))))
(when (< n end)
(if is-hexl
(vlf-tune-batch '(:hexl :dehexlify
:insert :encode))
(vlf-tune-batch '(:insert :encode)))
(vlf-tune-batch (if is-hexl
'(:hexl :dehexlify :insert :encode)
'(:insert :encode)))
(vlf-move-to-chunk-2 (- end vlf-batch-size) end)
(goto-char (point-max))
(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)
`(vlf-tune-approximate-nearby ,vec ,index)))
((zerop val) ;index has been tried before, yet still no value
(aset ,vec ,index
(vlf-tune-approximate-nearby ,vec ,index)))
,(if dont-approximate
`(aset ,vec ,index
(vlf-tune-approximate-nearby ,vec ,index))
`(vlf-tune-approximate-nearby ,vec ,index)))
(t val)))))
(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."
(interactive "p")
(vlf-verify-size)
(if (derived-mode-p 'hexl-mode)
(vlf-tune-conservative '(:hexl :dehexlify :insert :encode))
(vlf-tune-conservative '(:insert :encode)))
(vlf-tune-conservative (if (derived-mode-p 'hexl-mode)
'(:hexl :dehexlify :insert :encode)
'(:insert :encode)))
(let* ((end (min (+ vlf-end-pos (* vlf-batch-size (abs append)))
vlf-file-size))
(start (if (< append 0)
@ -191,9 +191,9 @@ When prefix argument is negative
(interactive "p")
(if (zerop vlf-start-pos)
(error "Already at BOF"))
(if (derived-mode-p 'hexl-mode)
(vlf-tune-conservative '(:hexl :dehexlify :insert :encode))
(vlf-tune-conservative '(:insert :encode)))
(vlf-tune-conservative (if (derived-mode-p 'hexl-mode)
'(:hexl :dehexlify :insert :encode)
'(:insert :encode)))
(let* ((start (max 0 (- vlf-start-pos (* vlf-batch-size (abs prepend)))))
(end (if (< prepend 0)
vlf-end-pos
@ -271,18 +271,18 @@ with the prefix argument DECREASE it is halved."
(defun vlf-beginning-of-file ()
"Jump to beginning of file content."
(interactive)
(if (derived-mode-p 'hexl-mode)
(vlf-tune-conservative '(:hexl :dehexlify :insert :encode))
(vlf-tune-conservative '(:insert :encode)))
(vlf-tune-conservative (if (derived-mode-p 'hexl-mode)
'(:hexl :dehexlify :insert :encode)
'(:insert :encode)))
(vlf-move-to-batch 0))
(defun vlf-end-of-file ()
"Jump to end of file content."
(interactive)
(vlf-verify-size)
(if (derived-mode-p 'hexl-mode)
(vlf-tune-conservative '(:hexl :dehexlify :insert :encode))
(vlf-tune-conservative '(:insert :encode)))
(vlf-tune-conservative (if (derived-mode-p 'hexl-mode)
'(:hexl :dehexlify :insert :encode)
'(:insert :encode)))
(vlf-move-to-batch vlf-file-size))
(defun vlf-revert (&optional _auto noconfirm)
@ -298,6 +298,9 @@ Ask for confirmation if NOCONFIRM is nil."
(defun vlf-jump-to-chunk (n)
"Go to to chunk N."
(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)))
(defun vlf-no-modifications ()