[gnus git] branch master updated: n0-17-325-g27d9bdb =1= (pop3-wait-for-messages): Rewrite to take linear time instead of exponential time.

Lars Magne Ingebrigtsen <[email protected]>
Newsgroups gmane.emacs.gnus.cvs
Message-ID <[email protected]>
       via  27d9bdbd6c8010ee821a049d7054f81e9d758c7d (commit)
      from  ebbd2fd67aa7a7216e070a33f5d73d44b50bc9de (commit)


- Log -----------------------------------------------------------------
commit 27d9bdbd6c8010ee821a049d7054f81e9d758c7d
Author: Lars Magne Ingebrigtsen <[email protected]>
Date:   Mon Sep 26 20:36:03 2011 +0200

    (pop3-wait-for-messages): Rewrite to take linear time instead of exponential time.

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 2e02c3c..72641de 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,9 @@
+2011-09-26  Lars Magne Ingebrigtsen  <[email protected]>
+
+	* pop3.el (pop3-number-of-responses): Removed.
+	(pop3-wait-for-messages): Rewrite to take linear time instead of
+	exponential time.
+
 2011-09-24  Lars Magne Ingebrigtsen  <[email protected]>
 
 	* gnus-sum.el (gnus-summary-show-article): Bind `shr-ignore-cache' to
diff --git a/lisp/pop3.el b/lisp/pop3.el
index 8fd5382..ee3e658 100644
--- a/lisp/pop3.el
+++ b/lisp/pop3.el
@@ -167,17 +167,30 @@ Use streaming commands."
 
 (defun pop3-send-streaming-command (process command count total-size)
   (erase-buffer)
-  (let ((i 1))
+  (let ((i 1)
+	(start-point (point-min))
+	(waited-for 0))
     (while (>= count i)
       (process-send-string process (format "%s %d\r\n" command i))
       ;; Only do 100 messages at a time to avoid pipe stalls.
       (when (zerop (% i pop3-stream-length))
-	(pop3-wait-for-messages process i total-size))
-      (incf i)))
-  (pop3-wait-for-messages process count total-size))
-
-(defun pop3-wait-for-messages (process count total-size)
-  (while (< (pop3-number-of-responses total-size) count)
+	(setq start-point
+	      (pop3-wait-for-messages process pop3-stream-length
+				      total-size start-point))
+	(incf waited-for pop3-stream-length))
+      (incf i))
+    (pop3-wait-for-messages process (- count waited-for)
+			    total-size start-point)))
+
+(defun pop3-wait-for-messages (process count total-size start-point)
+  (while (> count 0)
+    (goto-char start-point)
+    (while (or (and (re-search-forward "^\\+OK" nil t)
+		    (or (not total-size)
+			(re-search-forward "^\\.\r?\n" nil t)))
+	       (re-search-forward "^-ERR " nil t))
+      (decf count)
+      (setq start-point (point)))
     (unless (memq (process-status process) '(open run))
       (error "pop3 process died"))
     (when total-size
@@ -185,7 +198,8 @@ Use streaming commands."
 	       (truncate (/ (buffer-size) 1000))
 	       (truncate (* (/ (* (buffer-size) 1.0)
 			       total-size) 100))))
-    (pop3-accept-process-output process)))
+    (pop3-accept-process-output process))
+  start-point)
 
 (defun pop3-write-to-file (file)
   (let ((pop-buffer (current-buffer))
@@ -219,17 +233,6 @@ Use streaming commands."
 	  (delete-char 1))
 	(write-region (point-min) (point-max) file nil 'nomesg)))))
 
-(defun pop3-number-of-responses (endp)
-  (let ((responses 0))
-    (save-excursion
-      (goto-char (point-min))
-      (while (or (and (re-search-forward "^\\+OK" nil t)
-		      (or (not endp)
-			  (re-search-forward "^\\.\r?\n" nil t)))
-		 (re-search-forward "^-ERR " nil t))
-	(incf responses)))
-    responses))
-
 (defun pop3-logon (process)
   (let ((pop3-password pop3-password))
     ;; for debugging only

-----------------------------------------------------------------------
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we listed those
revisions in full, above.

Summary of changes:
 lisp/ChangeLog |    6 ++++++
 lisp/pop3.el   |   41 ++++++++++++++++++++++-------------------
 2 files changed, 28 insertions(+), 19 deletions(-)

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Gnus Project".

The branch, master has been updated


hooks/post-receive
-- 
Gnus Project
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.