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

Optimize goto-line for hexl-mode, no need to search.

This commit is contained in:
Andrey Kotlarski 2014-09-25 01:25:48 +03:00
parent b9187918f7
commit e4a2e806c9

View File

@ -207,6 +207,8 @@ 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: "))))
(if (derived-mode-p 'hexl-mode)
(vlf-goto-line-hexl n)
(run-hook-with-args 'vlf-before-batch-functions 'goto-line) (run-hook-with-args 'vlf-before-batch-functions 'goto-line)
(vlf-verify-size) (vlf-verify-size)
(let ((tramp-verbose (if (boundp 'tramp-verbose) (let ((tramp-verbose (if (boundp 'tramp-verbose)
@ -215,7 +217,6 @@ Search is performed chunk by chunk in `vlf-batch-size' memory."
(end-pos vlf-end-pos) (end-pos vlf-end-pos)
(batch-size vlf-batch-size) (batch-size vlf-batch-size)
(pos (point)) (pos (point))
(is-hexl (derived-mode-p 'hexl-mode))
(font-lock font-lock-mode) (font-lock font-lock-mode)
(time (float-time)) (time (float-time))
(success nil)) (success nil))
@ -232,7 +233,6 @@ Search is performed chunk by chunk in `vlf-batch-size' memory."
(inhibit-read-only t)) (inhibit-read-only t))
(setq n (1- n)) (setq n (1- n))
(vlf-with-undo-disabled (vlf-with-undo-disabled
(or is-hexl
(while (and (< (- end start) n) (while (and (< (- end start) n)
(< n (- vlf-file-size start))) (< n (- vlf-file-size start)))
(erase-buffer) (erase-buffer)
@ -243,13 +243,11 @@ Search is performed chunk by chunk in `vlf-batch-size' memory."
(vlf-verify-size) (vlf-verify-size)
(vlf-tune-batch '(:raw)) (vlf-tune-batch '(:raw))
(setq start end (setq start end
end (min vlf-file-size end (min vlf-file-size (+ start
(+ start vlf-batch-size))) 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-tune-batch (if is-hexl (vlf-tune-batch '(:insert :encode))
'(:hexl :dehexlify :insert :encode)
'(: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
@ -263,7 +261,6 @@ Search is performed chunk by chunk in `vlf-batch-size' memory."
(inhibit-read-only t)) (inhibit-read-only t))
(setq n (- n)) (setq n (- n))
(vlf-with-undo-disabled (vlf-with-undo-disabled
(or is-hexl
(while (and (< (- end start) n) (< n end)) (while (and (< (- end start) n) (< n end))
(erase-buffer) (erase-buffer)
(vlf-tune-insert-file-contents-literally start end) (vlf-tune-insert-file-contents-literally start end)
@ -274,11 +271,9 @@ Search is performed chunk by chunk in `vlf-batch-size' memory."
(setq end start (setq end start
start (max 0 (- end vlf-batch-size))) start (max 0 (- end vlf-batch-size)))
(progress-reporter-update reporter (progress-reporter-update reporter
(- vlf-file-size end)))) (- vlf-file-size end)))
(when (< n end) (when (< n end)
(vlf-tune-batch (if is-hexl (vlf-tune-batch '(:insert :encode))
'(:hexl :dehexlify :insert :encode)
'(: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
@ -291,7 +286,30 @@ Search is performed chunk by chunk in `vlf-batch-size' memory."
(goto-char pos) (goto-char pos)
(setq vlf-batch-size batch-size) (setq vlf-batch-size batch-size)
(message "Unable to find line")) (message "Unable to find line"))
(run-hook-with-args 'vlf-after-batch-functions 'goto-line)))) (run-hook-with-args 'vlf-after-batch-functions 'goto-line)))))
(defun vlf-goto-line-hexl (n)
"Go to line N. If N is negative, count from the end of file.
Assume `hexl-mode' is active."
(vlf-tune-load '(:hexl :raw))
(if (< n 0)
(let ((hidden-bytes (+ vlf-file-size (* n hexl-bits))))
(setq hidden-bytes (- hidden-bytes (mod hidden-bytes
vlf-batch-size)))
(vlf-move-to-batch hidden-bytes)
(goto-char (point-max))
(forward-line (+ (round (- vlf-file-size
(min vlf-file-size
(+ hidden-bytes
vlf-batch-size)))
hexl-bits)
n)))
(let ((hidden-bytes (1- (* n hexl-bits))))
(setq hidden-bytes (- hidden-bytes (mod hidden-bytes
vlf-batch-size)))
(vlf-move-to-batch hidden-bytes)
(goto-char (point-min))
(forward-line (- n 1 (/ hidden-bytes hexl-bits))))))
(provide 'vlf-search) (provide 'vlf-search)