mirror of
				https://github.com/m00natic/vlfi.git
				synced 2025-10-30 22:53:37 +00:00 
			
		
		
		
	Optimize search a bit.
This commit is contained in:
		
							
								
								
									
										35
									
								
								vlfi.el
									
									
									
									
									
								
							
							
						
						
									
										35
									
								
								vlfi.el
									
									
									
									
									
								
							| @@ -277,17 +277,18 @@ OP-TYPE specifies the file operation being performed over FILENAME." | |||||||
|           (if backward |           (if backward | ||||||
|               (while (not (zerop to-find)) |               (while (not (zerop to-find)) | ||||||
|                 (cond ((re-search-backward regexp nil t) |                 (cond ((re-search-backward regexp nil t) | ||||||
|                        (setq match-start-pos (+ vlfi-start-pos |  | ||||||
|                                                 (match-beginning 0))) |  | ||||||
|                        (let ((new-match-end (+ vlfi-start-pos |  | ||||||
|                                                (match-end 0)))) |  | ||||||
|                          (if (< new-match-end match-end-pos) |  | ||||||
|                        (setq to-find (1- to-find) |                        (setq to-find (1- to-find) | ||||||
|                                    match-end-pos new-match-end)))) |                              match-start-pos (+ vlfi-start-pos | ||||||
|  |                                                 (match-beginning 0)) | ||||||
|  |                              match-end-pos (+ vlfi-start-pos | ||||||
|  |                                               (match-end 0)))) | ||||||
|                       ((zerop vlfi-start-pos) |                       ((zerop vlfi-start-pos) | ||||||
|                        (throw 'end-of-file nil)) |                        (throw 'end-of-file nil)) | ||||||
|                       (t (vlfi-move-to-batch (- vlfi-start-pos |                       (t (let ((half-move (- vlfi-start-pos half-batch))) | ||||||
|                                                 half-batch)) |                            (vlfi-move-to-batch | ||||||
|  |                             (if (< match-start-pos half-move) | ||||||
|  |                                 (- match-start-pos vlfi-batch-size) | ||||||
|  |                               half-move))) | ||||||
|                          (goto-char (if (< match-start-pos |                          (goto-char (if (< match-start-pos | ||||||
|                                            vlfi-end-pos) |                                            vlfi-end-pos) | ||||||
|                                         (- match-start-pos |                                         (- match-start-pos | ||||||
| @@ -297,16 +298,18 @@ OP-TYPE specifies the file operation being performed over FILENAME." | |||||||
|                                                    vlfi-start-pos)))) |                                                    vlfi-start-pos)))) | ||||||
|             (while (not (zerop to-find)) |             (while (not (zerop to-find)) | ||||||
|               (cond ((re-search-forward regexp nil t) |               (cond ((re-search-forward regexp nil t) | ||||||
|                      (setq match-end-pos (+ vlfi-start-pos |  | ||||||
|                                             (match-end 0))) |  | ||||||
|                      (let ((new-match-start (+ vlfi-start-pos |  | ||||||
|                                                (match-beginning 0)))) |  | ||||||
|                        (if (< match-start-pos new-match-start) |  | ||||||
|                      (setq to-find (1- to-find) |                      (setq to-find (1- to-find) | ||||||
|                                  match-start-pos new-match-start)))) |                            match-start-pos (+ vlfi-start-pos | ||||||
|  |                                               (match-beginning 0)) | ||||||
|  |                            match-end-pos (+ vlfi-start-pos | ||||||
|  |                                             (match-end 0)))) | ||||||
|                     ((= vlfi-end-pos vlfi-file-size) |                     ((= vlfi-end-pos vlfi-file-size) | ||||||
|                      (throw 'end-of-file nil)) |                      (throw 'end-of-file nil)) | ||||||
|                     (t (vlfi-move-to-batch (- vlfi-end-pos half-batch)) |                     (t (let ((half-move (- vlfi-end-pos half-batch))) | ||||||
|  |                          (vlfi-move-to-batch | ||||||
|  |                           (if (< half-move match-end-pos) | ||||||
|  |                               match-end-pos | ||||||
|  |                             half-move))) | ||||||
|                        (goto-char (if (< vlfi-start-pos match-end-pos) |                        (goto-char (if (< vlfi-start-pos match-end-pos) | ||||||
|                                       (- match-end-pos vlfi-start-pos) |                                       (- match-end-pos vlfi-start-pos) | ||||||
|                                     (point-min))) |                                     (point-min))) | ||||||
| @@ -341,7 +344,7 @@ successful.  Return nil if nothing found." | |||||||
|  |  | ||||||
| (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." | ||||||
|   (interactive (list (read-regexp "Search whole file" |   (interactive (list (read-regexp "Search whole file backward" | ||||||
|                                   (if regexp-history |                                   (if regexp-history | ||||||
|                                       (car regexp-history)) |                                       (car regexp-history)) | ||||||
|                                   'regexp-history) |                                   'regexp-history) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user