mirror of
				https://github.com/m00natic/vlfi.git
				synced 2025-10-30 22:53:37 +00:00 
			
		
		
		
	Optimize a bit goto line.
This commit is contained in:
		
							
								
								
									
										16
									
								
								vlfi.el
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								vlfi.el
									
									
									
									
									
								
							| @@ -370,8 +370,9 @@ Return number of bytes moved back for this to happen." | |||||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||||
| ;;; search | ;;; search | ||||||
|  |  | ||||||
| (defun vlfi-re-search (regexp count backward) | (defun vlfi-re-search (regexp count backward batch-step) | ||||||
|   "Search for REGEXP COUNT number of times forward or BACKWARD." |   "Search for REGEXP COUNT number of times forward or BACKWARD. | ||||||
|  | BATCH-STEP is amount of overlap between successive chunks." | ||||||
|   (let* ((match-chunk-start vlfi-start-pos) |   (let* ((match-chunk-start vlfi-start-pos) | ||||||
|          (match-chunk-end vlfi-end-pos) |          (match-chunk-end vlfi-end-pos) | ||||||
|          (match-start-pos (+ vlfi-start-pos (position-bytes (point)))) |          (match-start-pos (+ vlfi-start-pos (position-bytes (point)))) | ||||||
| @@ -382,8 +383,7 @@ Return number of bytes moved back for this to happen." | |||||||
|                     (if backward |                     (if backward | ||||||
|                         (- vlfi-file-size vlfi-end-pos) |                         (- vlfi-file-size vlfi-end-pos) | ||||||
|                       vlfi-start-pos) |                       vlfi-start-pos) | ||||||
|                     vlfi-file-size)) |                     vlfi-file-size))) | ||||||
|          (batch-step (/ vlfi-batch-size 8))) ; amount of chunk overlap |  | ||||||
|     (unwind-protect |     (unwind-protect | ||||||
|         (catch 'end-of-file |         (catch 'end-of-file | ||||||
|           (if backward |           (if backward | ||||||
| @@ -494,7 +494,7 @@ Search is performed chunk by chunk in `vlfi-batch-size' memory." | |||||||
|                                   (if regexp-history |                                   (if regexp-history | ||||||
|                                       (car regexp-history))) |                                       (car regexp-history))) | ||||||
|                      (or current-prefix-arg 1))) |                      (or current-prefix-arg 1))) | ||||||
|   (vlfi-re-search regexp count nil)) |   (vlfi-re-search regexp count nil (/ vlfi-batch-size 8))) | ||||||
|  |  | ||||||
| (defun vlfi-re-search-backward (regexp count) | (defun vlfi-re-search-backward (regexp count) | ||||||
|   "Search backward for REGEXP prefix COUNT number of times. |   "Search backward for REGEXP prefix COUNT number of times. | ||||||
| @@ -503,7 +503,7 @@ Search is performed chunk by chunk in `vlfi-batch-size' memory." | |||||||
|                                   (if regexp-history |                                   (if regexp-history | ||||||
|                                       (car regexp-history))) |                                       (car regexp-history))) | ||||||
|                      (or current-prefix-arg 1))) |                      (or current-prefix-arg 1))) | ||||||
|   (vlfi-re-search regexp count t)) |   (vlfi-re-search regexp count t (/ vlfi-batch-size 8))) | ||||||
|  |  | ||||||
| (defun vlfi-goto-line (n) | (defun vlfi-goto-line (n) | ||||||
|   "Go to line N." |   "Go to line N." | ||||||
| @@ -515,8 +515,8 @@ Search is performed chunk by chunk in `vlfi-batch-size' memory." | |||||||
|     (unwind-protect |     (unwind-protect | ||||||
|         (progn (vlfi-beginning-of-file) |         (progn (vlfi-beginning-of-file) | ||||||
|                (goto-char (point-min)) |                (goto-char (point-min)) | ||||||
|                (setq success (vlfi-re-search-forward "[\n\C-m]" |                (setq success (vlfi-re-search "[\n\C-m]" (1- n) | ||||||
|                                                      (1- n)))) |                                              nil 0))) | ||||||
|       (unless success |       (unless success | ||||||
|         (vlfi-move-to-chunk start-pos end-pos) |         (vlfi-move-to-chunk start-pos end-pos) | ||||||
|         (goto-char pos))))) |         (goto-char pos))))) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user