mirror of
https://github.com/m00natic/vlfi.git
synced 2025-02-22 21:08:05 +00:00
Optimize goto-line for hexl-mode, no need to search.
This commit is contained in:
parent
b9187918f7
commit
e4a2e806c9
178
vlf-search.el
178
vlf-search.el
@ -207,91 +207,109 @@ 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: "))))
|
||||||
(run-hook-with-args 'vlf-before-batch-functions 'goto-line)
|
(if (derived-mode-p 'hexl-mode)
|
||||||
(vlf-verify-size)
|
(vlf-goto-line-hexl n)
|
||||||
(let ((tramp-verbose (if (boundp 'tramp-verbose)
|
(run-hook-with-args 'vlf-before-batch-functions 'goto-line)
|
||||||
(min tramp-verbose 2)))
|
(vlf-verify-size)
|
||||||
(start-pos vlf-start-pos)
|
(let ((tramp-verbose (if (boundp 'tramp-verbose)
|
||||||
(end-pos vlf-end-pos)
|
(min tramp-verbose 2)))
|
||||||
(batch-size vlf-batch-size)
|
(start-pos vlf-start-pos)
|
||||||
(pos (point))
|
(end-pos vlf-end-pos)
|
||||||
(is-hexl (derived-mode-p 'hexl-mode))
|
(batch-size vlf-batch-size)
|
||||||
(font-lock font-lock-mode)
|
(pos (point))
|
||||||
(time (float-time))
|
(font-lock font-lock-mode)
|
||||||
(success nil))
|
(time (float-time))
|
||||||
(font-lock-mode 0)
|
(success nil))
|
||||||
(vlf-tune-batch '(:raw))
|
(font-lock-mode 0)
|
||||||
(unwind-protect
|
(vlf-tune-batch '(:raw))
|
||||||
(if (< 0 n)
|
(unwind-protect
|
||||||
(let ((start 0)
|
(if (< 0 n)
|
||||||
(end (min vlf-batch-size vlf-file-size))
|
(let ((start 0)
|
||||||
|
(end (min vlf-batch-size vlf-file-size))
|
||||||
|
(reporter (make-progress-reporter
|
||||||
|
(concat "Searching for line "
|
||||||
|
(number-to-string n) "...")
|
||||||
|
0 vlf-file-size))
|
||||||
|
(inhibit-read-only t))
|
||||||
|
(setq n (1- n))
|
||||||
|
(vlf-with-undo-disabled
|
||||||
|
(while (and (< (- end start) n)
|
||||||
|
(< n (- vlf-file-size start)))
|
||||||
|
(erase-buffer)
|
||||||
|
(vlf-tune-insert-file-contents-literally start end)
|
||||||
|
(goto-char (point-min))
|
||||||
|
(while (re-search-forward "[\n\C-m]" nil t)
|
||||||
|
(setq n (1- n)))
|
||||||
|
(vlf-verify-size)
|
||||||
|
(vlf-tune-batch '(:raw))
|
||||||
|
(setq start end
|
||||||
|
end (min vlf-file-size (+ start
|
||||||
|
vlf-batch-size)))
|
||||||
|
(progress-reporter-update reporter start))
|
||||||
|
(when (< n (- vlf-file-size end))
|
||||||
|
(vlf-tune-batch '(: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
|
||||||
|
reporter time)))))
|
||||||
|
(let ((start (max 0 (- vlf-file-size vlf-batch-size)))
|
||||||
|
(end vlf-file-size)
|
||||||
(reporter (make-progress-reporter
|
(reporter (make-progress-reporter
|
||||||
(concat "Searching for line "
|
(concat "Searching for line -"
|
||||||
(number-to-string n) "...")
|
(number-to-string n) "...")
|
||||||
0 vlf-file-size))
|
0 vlf-file-size))
|
||||||
(inhibit-read-only t))
|
(inhibit-read-only t))
|
||||||
(setq n (1- 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)
|
(erase-buffer)
|
||||||
(< n (- vlf-file-size start)))
|
(vlf-tune-insert-file-contents-literally start end)
|
||||||
(erase-buffer)
|
(goto-char (point-max))
|
||||||
(vlf-tune-insert-file-contents-literally start end)
|
(while (re-search-backward "[\n\C-m]" nil t)
|
||||||
(goto-char (point-min))
|
(setq n (1- n)))
|
||||||
(while (re-search-forward "[\n\C-m]" nil t)
|
(vlf-tune-batch '(:raw))
|
||||||
(setq n (1- n)))
|
(setq end start
|
||||||
(vlf-verify-size)
|
start (max 0 (- end vlf-batch-size)))
|
||||||
(vlf-tune-batch '(:raw))
|
(progress-reporter-update reporter
|
||||||
(setq start end
|
(- vlf-file-size end)))
|
||||||
end (min vlf-file-size
|
(when (< n end)
|
||||||
(+ start vlf-batch-size)))
|
(vlf-tune-batch '(:insert :encode))
|
||||||
(progress-reporter-update reporter start)))
|
(vlf-move-to-chunk-2 (- end vlf-batch-size) end)
|
||||||
(when (< n (- vlf-file-size end))
|
(goto-char (point-max))
|
||||||
(vlf-tune-batch (if is-hexl
|
(setq success (vlf-re-search "[\n\C-m]" n t 0
|
||||||
'(:hexl :dehexlify :insert :encode)
|
reporter time))))))
|
||||||
'(:insert :encode)))
|
(if font-lock (font-lock-mode 1))
|
||||||
(vlf-move-to-chunk-2 start (+ start vlf-batch-size))
|
(unless success
|
||||||
(goto-char (point-min))
|
(vlf-with-undo-disabled
|
||||||
(setq success (vlf-re-search "[\n\C-m]" n nil 0
|
(vlf-move-to-chunk-2 start-pos end-pos))
|
||||||
reporter time)))))
|
(vlf-update-buffer-name)
|
||||||
(let ((start (max 0 (- vlf-file-size vlf-batch-size)))
|
(goto-char pos)
|
||||||
(end vlf-file-size)
|
(setq vlf-batch-size batch-size)
|
||||||
(reporter (make-progress-reporter
|
(message "Unable to find line"))
|
||||||
(concat "Searching for line -"
|
(run-hook-with-args 'vlf-after-batch-functions 'goto-line)))))
|
||||||
(number-to-string n) "...")
|
|
||||||
0 vlf-file-size))
|
(defun vlf-goto-line-hexl (n)
|
||||||
(inhibit-read-only t))
|
"Go to line N. If N is negative, count from the end of file.
|
||||||
(setq n (- n))
|
Assume `hexl-mode' is active."
|
||||||
(vlf-with-undo-disabled
|
(vlf-tune-load '(:hexl :raw))
|
||||||
(or is-hexl
|
(if (< n 0)
|
||||||
(while (and (< (- end start) n) (< n end))
|
(let ((hidden-bytes (+ vlf-file-size (* n hexl-bits))))
|
||||||
(erase-buffer)
|
(setq hidden-bytes (- hidden-bytes (mod hidden-bytes
|
||||||
(vlf-tune-insert-file-contents-literally start end)
|
vlf-batch-size)))
|
||||||
(goto-char (point-max))
|
(vlf-move-to-batch hidden-bytes)
|
||||||
(while (re-search-backward "[\n\C-m]" nil t)
|
(goto-char (point-max))
|
||||||
(setq n (1- n)))
|
(forward-line (+ (round (- vlf-file-size
|
||||||
(vlf-tune-batch '(:raw))
|
(min vlf-file-size
|
||||||
(setq end start
|
(+ hidden-bytes
|
||||||
start (max 0 (- end vlf-batch-size)))
|
vlf-batch-size)))
|
||||||
(progress-reporter-update reporter
|
hexl-bits)
|
||||||
(- vlf-file-size end))))
|
n)))
|
||||||
(when (< n end)
|
(let ((hidden-bytes (1- (* n hexl-bits))))
|
||||||
(vlf-tune-batch (if is-hexl
|
(setq hidden-bytes (- hidden-bytes (mod hidden-bytes
|
||||||
'(:hexl :dehexlify :insert :encode)
|
vlf-batch-size)))
|
||||||
'(:insert :encode)))
|
(vlf-move-to-batch hidden-bytes)
|
||||||
(vlf-move-to-chunk-2 (- end vlf-batch-size) end)
|
(goto-char (point-min))
|
||||||
(goto-char (point-max))
|
(forward-line (- n 1 (/ hidden-bytes hexl-bits))))))
|
||||||
(setq success (vlf-re-search "[\n\C-m]" n t 0
|
|
||||||
reporter time))))))
|
|
||||||
(if font-lock (font-lock-mode 1))
|
|
||||||
(unless success
|
|
||||||
(vlf-with-undo-disabled
|
|
||||||
(vlf-move-to-chunk-2 start-pos end-pos))
|
|
||||||
(vlf-update-buffer-name)
|
|
||||||
(goto-char pos)
|
|
||||||
(setq vlf-batch-size batch-size)
|
|
||||||
(message "Unable to find line"))
|
|
||||||
(run-hook-with-args 'vlf-after-batch-functions 'goto-line))))
|
|
||||||
|
|
||||||
(provide 'vlf-search)
|
(provide 'vlf-search)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user