[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/vlf e4a2e80 266/310: Optimize goto-line for hexl-mode,
From: |
Stefan Monnier |
Subject: |
[elpa] externals/vlf e4a2e80 266/310: Optimize goto-line for hexl-mode, no need to search. |
Date: |
Sat, 28 Nov 2020 00:33:29 -0500 (EST) |
branch: externals/vlf
commit e4a2e806c9cd3ec7dbbb302e52d4ecb3b327c889
Author: Andrey Kotlarski <m00naticus@gmail.com>
Commit: Andrey Kotlarski <m00naticus@gmail.com>
Optimize goto-line for hexl-mode, no need to search.
---
vlf-search.el | 178 ++++++++++++++++++++++++++++++++--------------------------
1 file changed, 98 insertions(+), 80 deletions(-)
diff --git a/vlf-search.el b/vlf-search.el
index 4abdf2c..ec668f2 100644
--- a/vlf-search.el
+++ b/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."
(interactive (if (vlf-no-modifications)
(list (read-number "Go to line: "))))
- (run-hook-with-args 'vlf-before-batch-functions 'goto-line)
- (vlf-verify-size)
- (let ((tramp-verbose (if (boundp 'tramp-verbose)
- (min tramp-verbose 2)))
- (start-pos vlf-start-pos)
- (end-pos vlf-end-pos)
- (batch-size vlf-batch-size)
- (pos (point))
- (is-hexl (derived-mode-p 'hexl-mode))
- (font-lock font-lock-mode)
- (time (float-time))
- (success nil))
- (font-lock-mode 0)
- (vlf-tune-batch '(:raw))
- (unwind-protect
- (if (< 0 n)
- (let ((start 0)
- (end (min vlf-batch-size vlf-file-size))
+ (if (derived-mode-p 'hexl-mode)
+ (vlf-goto-line-hexl n)
+ (run-hook-with-args 'vlf-before-batch-functions 'goto-line)
+ (vlf-verify-size)
+ (let ((tramp-verbose (if (boundp 'tramp-verbose)
+ (min tramp-verbose 2)))
+ (start-pos vlf-start-pos)
+ (end-pos vlf-end-pos)
+ (batch-size vlf-batch-size)
+ (pos (point))
+ (font-lock font-lock-mode)
+ (time (float-time))
+ (success nil))
+ (font-lock-mode 0)
+ (vlf-tune-batch '(:raw))
+ (unwind-protect
+ (if (< 0 n)
+ (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
- (concat "Searching for line "
+ (concat "Searching for line -"
(number-to-string n) "...")
0 vlf-file-size))
(inhibit-read-only t))
- (setq n (1- n))
+ (setq n (- n))
(vlf-with-undo-disabled
- (or is-hexl
- (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 (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
- reporter time)))))
- (let ((start (max 0 (- vlf-file-size vlf-batch-size)))
- (end 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 (- n))
- (vlf-with-undo-disabled
- (or is-hexl
- (while (and (< (- end start) n) (< n end))
- (erase-buffer)
- (vlf-tune-insert-file-contents-literally start end)
- (goto-char (point-max))
- (while (re-search-backward "[\n\C-m]" nil t)
- (setq n (1- n)))
- (vlf-tune-batch '(:raw))
- (setq end start
- start (max 0 (- end vlf-batch-size)))
- (progress-reporter-update reporter
- (- vlf-file-size end))))
- (when (< n end)
- (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
- 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))))
+ (while (and (< (- end start) n) (< n end))
+ (erase-buffer)
+ (vlf-tune-insert-file-contents-literally start end)
+ (goto-char (point-max))
+ (while (re-search-backward "[\n\C-m]" nil t)
+ (setq n (1- n)))
+ (vlf-tune-batch '(:raw))
+ (setq end start
+ start (max 0 (- end vlf-batch-size)))
+ (progress-reporter-update reporter
+ (- vlf-file-size end)))
+ (when (< n end)
+ (vlf-tune-batch '(: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
+ 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)))))
+
+(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)
- [elpa] externals/vlf e8bb4a9 248/310: Apply batch size tuning on adjacent moves, search, save adjusting and, (continued)
- [elpa] externals/vlf e8bb4a9 248/310: Apply batch size tuning on adjacent moves, search, save adjusting and, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf d526ea8 257/310: Apply and restore batch size in more cases., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 9b6657b 260/310: Replace usage of conservative tune in single batch operations with load, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 2c660b0 269/310: Fix positive goto-line search and make highlighting of match optional., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 3cfa9b1 273/310: Refactor vlf-query-replace and don't adjust batch size if only, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 61599a0 274/310: Change linear tune to search only known measures and use it to, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf a9c14e2 268/310: Add regexp query replace over whole file command., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 673ae08 277/310: Lower tramp verbosity level., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf ac8d400 276/310: Fixes to hexl-mode activation., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf f63ea96 272/310: Document new query replace and save options., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf e4a2e80 266/310: Optimize goto-line for hexl-mode, no need to search.,
Stefan Monnier <=
- [elpa] externals/vlf 7b9befe 275/310: - don't load unnecessary data at the end of search or occur, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 842569a 270/310: Add ability to use temporary file when adjusting content on save., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf d579b7b 279/310: Workaround local maximum in batch tune., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf b14c912 290/310: Copy around buffer specific profile vectors when forking new buffers., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf b300137 292/310: Encode smaller region to detect cut point overall offset in vlf-occur, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 86be483 293/310: Improve search precision., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf a8ba836 298/310: Fix issue where tramp-verbose is bound to nil., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 25e16ef 303/310: Fix broken link in README, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf b62bc04 301/310: Issue 31 Make vlf-batch-size configurable in the remote case, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 55e0c40 300/310: Explicitly set coding-system-for-read to the current coding when not, Stefan Monnier, 2020/11/28