# HG changeset patch # User adrian # Date 1109196555 0 # Node ID 16738b49b83368709e8881eae65f0ebdb2fc4123 # Parent c2580215c2222782dc1bd6cb3b32f3927b38d91b [xemacs-hg @ 2005-02-23 22:09:13 by adrian] [PATCH] xemacs-21.5-clean: Avoid prohibitive string consing and GC diff -r c2580215c222 -r 16738b49b833 lisp/ChangeLog --- a/lisp/ChangeLog Wed Feb 23 18:56:44 2005 +0000 +++ b/lisp/ChangeLog Wed Feb 23 22:09:15 2005 +0000 @@ -1,3 +1,10 @@ +2005-02-20 Adrian Aichner + + * replace.el (operate-on-non-matching-lines): Append matching + lines to temp buffer to avoid prohibitive GC as a result of + enormous string consing. + * replace.el (operate-on-matching-lines): Ditto. + 2005-02-21 Ben Wing * glyphs.el: diff -r c2580215c222 -r 16738b49b833 lisp/replace.el --- a/lisp/replace.el Wed Feb 23 18:56:44 2005 +0000 +++ b/lisp/replace.el Wed Feb 23 22:09:15 2005 +0000 @@ -247,7 +247,9 @@ (let ((matched-text nil) (curmatch-start (point)) - (limit (copy-marker (point-max)))) + (limit (copy-marker (point-max))) + (matched-text-buffer (generate-new-buffer " *matched-text*")) + lines-matched) ;; Limit search if limits were specified. (when end (setq limit (copy-marker end))) @@ -259,32 +261,33 @@ ;; curmatch-start is first char not preserved by previous match. (if (not (re-search-forward regexp limit 'move)) (let ((curmatch-end limit)) - (setq matched-text (concat matched-text (buffer-substring curmatch-start curmatch-end))) + (append-to-buffer matched-text-buffer curmatch-start curmatch-end) (if delete (delete-region curmatch-start curmatch-end))) (let ((curmatch-end (save-excursion (goto-char (match-beginning 0)) - (beginning-of-line) - (point)))) + (beginning-of-line) + (point)))) ;; Now curmatch-end is first char preserved by the new match. (if (< curmatch-start curmatch-end) (progn - (setq matched-text (concat matched-text (buffer-substring curmatch-start curmatch-end))) + (append-to-buffer matched-text-buffer curmatch-start curmatch-end) (if delete (delete-region curmatch-start curmatch-end)))))) (setq curmatch-start (save-excursion (forward-line 1) - (point))) + (point))) ;; If the match was empty, avoid matching again at same place. (and (not (eobp)) (= (match-beginning 0) (match-end 0)) (forward-char 1))) ;; If any lines were matched and KILL is non-nil, insert the ;; matched lines into the kill ring. + (setq matched-text (buffer-string matched-text-buffer)) (if (and matched-text kill) (kill-new matched-text)) ;; Return the number of matched lines. - (with-temp-buffer - ;; Use concat to make a string even if matched-text is nil. - (insert (concat matched-text)) - (count-lines (point-min) (point-max))) - )))) + (setq lines-matched + (with-current-buffer matched-text-buffer + (count-lines (point-min) (point-max)))) + (kill-buffer matched-text-buffer) + lines-matched)))) (define-function 'keep-lines 'delete-non-matching-lines) (defun delete-non-matching-lines (regexp) @@ -358,8 +361,9 @@ (let ((matched-text nil) (curmatch-start nil) (curmatch-end nil) - (limit nil)) - + (limit nil) + (matched-text-buffer (generate-new-buffer " *matched-text*")) + lines-matched) ;; Limit search if limits were specified. (when beg (goto-char beg)) (when end (setq limit (copy-marker end))) @@ -370,17 +374,17 @@ (beginning-of-line) (point))) (setq curmatch-end (progn (forward-line 1) (point))) - (setq matched-text (concat matched-text (buffer-substring curmatch-start curmatch-end))) + (append-to-buffer matched-text-buffer curmatch-start curmatch-end) (if delete (delete-region curmatch-start curmatch-end))) - + (setq matched-text (buffer-string matched-text-buffer)) (if (and matched-text kill) (kill-new matched-text)) ;; Return the number of matched lines. - (with-temp-buffer - ;; Use concat to make a string even if matched-text is nil. - (insert (concat matched-text)) - (count-lines (point-min) (point-max))) - )))) + (setq lines-matched + (with-current-buffer matched-text-buffer + (count-lines (point-min) (point-max)))) + (kill-buffer matched-text-buffer) + lines-matched)))) (define-function 'flush-lines 'delete-matching-lines) (defun delete-matching-lines (regexp)