From dbb776cc5fdd0602ceaf32e4860517dd02a59d56 Mon Sep 17 00:00:00 2001 From: murata Date: Sat, 20 May 2000 01:52:33 +0000 Subject: [PATCH] (elmo-use-overview-hashtb): New variable. If non-nil, use hash table for overview. (elmo-msgdb-overview-hashtb): New variable. (elmo-hash-maximum-size): New variable. (elmo-msgdb-make-overview-hashtb): New function. (elmo-msgdb-clear-overview-hashtb): New function. (elmo-clear-hash-val): New macro. All other related modules are changed. --- elmo/elmo-localdir.el | 7 ++- elmo/elmo-msgdb.el | 119 ++++++++++++++++++++++++++++++++++++++----------- elmo/elmo-util.el | 9 +++- elmo/elmo-vars.el | 8 +++- elmo/elmo2.el | 22 +++++---- 5 files changed, 127 insertions(+), 38 deletions(-) diff --git a/elmo/elmo-localdir.el b/elmo/elmo-localdir.el index aab6f01..572eca6 100644 --- a/elmo/elmo-localdir.el +++ b/elmo/elmo-localdir.el @@ -398,6 +398,7 @@ (onum-alist (elmo-msgdb-get-number-alist msgdb)) (omark-alist (elmo-msgdb-get-mark-alist msgdb)) (oov (elmo-msgdb-get-overview msgdb)) + (oovht (elmo-msgdb-get-overviewht msgdb)) i flist onum mark new-mark-alist total) (setq i 0) (setq flist @@ -420,7 +421,7 @@ ;; update overview (elmo-msgdb-overview-entity-set-number (elmo-msgdb-overview-get-entity-by-number - oov onum) i) + oov onum oovht) i) ;; update number-alist (setcar (assq onum onum-alist) i)) ;; update mark-alist @@ -434,7 +435,9 @@ (list (elmo-msgdb-get-overview msgdb) onum-alist new-mark-alist - (elmo-msgdb-get-location msgdb)))) + (elmo-msgdb-get-location msgdb) + ;; remake hash table + (elmo-msgdb-make-overview-hashtb (elmo-msgdb-get-overview msgdb))))) (defun elmo-localdir-use-cache-p (spec number) nil) diff --git a/elmo/elmo-msgdb.el b/elmo/elmo-msgdb.el index 492bf54..f9f0d63 100644 --- a/elmo/elmo-msgdb.el +++ b/elmo/elmo-msgdb.el @@ -37,6 +37,9 @@ (require 'std11) (require 'elmo-cache) +(defvar elmo-msgdb-overview-hashtb nil) +(make-variable-buffer-local 'elmo-msgdb-overview-hashtb) + (defun elmo-msgdb-expand-path (folder &optional spec) (convert-standard-filename (let* ((spec (or spec (elmo-folder-get-spec folder))) @@ -141,6 +144,8 @@ (caddr msgdb)) (defsubst elmo-msgdb-get-location (msgdb) (cadddr msgdb)) +(defsubst elmo-msgdb-get-overviewht (msgdb) + (nth 4 msgdb)) ;; ;; number <-> Message-ID handling @@ -373,8 +378,10 @@ header separator." (expand-file-name elmo-msgdb-number-filename dir))) (defun elmo-msgdb-overview-load (dir) - (elmo-object-load - (expand-file-name elmo-msgdb-overview-filename dir))) + (let ((overview (elmo-object-load + (expand-file-name elmo-msgdb-overview-filename dir)))) + (elmo-msgdb-make-overview-hashtb overview) + overview)) (defun elmo-msgdb-mark-load (dir) (elmo-object-load @@ -417,7 +424,9 @@ content of MSGDB is changed." (elmo-msgdb-number-load dir))) (mark-alist (or (caddr msgdb) (elmo-msgdb-mark-load dir))) - message-id) + (hashtb (or (elmo-msgdb-get-overviewht msgdb) + (elmo-msgdb-make-overview-hashtb overview))) + ov-entity message-id) ;; remove from current database. (while msg-list (setq message-id (cdr (assq (car msg-list) number-alist))) @@ -428,16 +437,20 @@ content of MSGDB is changed." ;(setq overview (delete (assoc message-id overview) overview)) (setq overview (delq - (elmo-msgdb-overview-get-entity-by-number overview - (car msg-list)) + (setq ov-entity + (elmo-msgdb-overview-get-entity-by-number + overview (car msg-list) hashtb)) overview)) + (when (and elmo-use-overview-hashtb hashtb) + (elmo-msgdb-clear-overview-hashtb ov-entity hashtb)) (setq number-alist (delq (assq (car msg-list) number-alist) number-alist)) (setq mark-alist (delq (assq (car msg-list) mark-alist) mark-alist)) (setq msg-list (cdr msg-list))) (setcar msgdb overview) (setcar (cdr msgdb) number-alist) - (setcar (cddr msgdb) mark-alist)) + (setcar (cddr msgdb) mark-alist) + (setcar (nthcdr 4 msgdb) hashtb)) t)) ;return value (defsubst elmo-msgdb-set-overview (msgdb overview) @@ -510,17 +523,27 @@ content of MSGDB is changed." (and extra (cdr (assoc field-name extra))))) -(defun elmo-msgdb-overview-get-entity-by-number (database number) - (let ((db database) - entity) - (catch 'loop - (while db - (if (eq (elmo-msgdb-overview-entity-get-number (car db)) number) - (progn - (setq entity (car db)) - (throw 'loop nil)) - (setq db (cdr db))))) - entity)) +(defun elmo-msgdb-overview-get-entity-by-number (database number &optional ht) + (when number + (if (or ht elmo-msgdb-overview-hashtb) + (elmo-get-hash-val (format "#%d" number) + (or ht elmo-msgdb-overview-hashtb)) + (let ((db database) + entity) + (catch 'loop + (while db + (if (eq (elmo-msgdb-overview-entity-get-number (car db)) number) + (progn + (setq entity (car db)) + (throw 'loop nil)) + (setq db (cdr db))))) + entity)))) + +(defsubst elmo-msgdb-overview-get-entity (database message-id &optional ht) + (if (or ht elmo-msgdb-overview-hashtb) + (and message-id + (elmo-get-hash-val message-id (or ht elmo-msgdb-overview-hashtb))) + (assoc message-id database))) ;; ;; deleted message handling @@ -704,19 +727,63 @@ Header region is supposed to be narrowed." (message "Sorting...done.") (list overview (nth 1 msgdb)(nth 2 msgdb)(nth 3 msgdb)))) -(defsubst elmo-msgdb-search-overview-entity (number number-alist overview) - (let ((message-id (cdr (assq number number-alist))) - ovs) - (if message-id - (assoc message-id overview) - (elmo-msgdb-overview-get-entity-by-number overview number)))) - -(defsubst elmo-msgdb-append (msgdb msgdb-append) +(defsubst elmo-msgdb-search-overview-entity (number number-alist overview + &optional ht) + (when number + (if (or ht elmo-msgdb-overview-hashtb) + (elmo-get-hash-val (format "#%d" number) + (or ht elmo-msgdb-overview-hashtb)) + (let ((message-id (cdr (assq number number-alist)))) + (if message-id + (assoc message-id overview) + (elmo-msgdb-overview-get-entity-by-number overview number)))))) + +(defun elmo-msgdb-clear-overview-hashtb (entity &optional hashtb) + (let ((hashtb (or hashtb elmo-msgdb-overview-hashtb)) + number) + (when (and entity + elmo-use-overview-hashtb + hashtb) + (and (setq number (elmo-msgdb-overview-entity-get-number entity)) + (elmo-clear-hash-val (format "#%d" number) hashtb)) + (and (car entity) ;; message-id + (elmo-clear-hash-val (car entity) hashtb))))) + +(defun elmo-msgdb-make-overview-hashtb (overview &optional hashtb) + (if elmo-use-overview-hashtb + (let ((hashtb (or hashtb ;; append + (setq elmo-msgdb-overview-hashtb + (elmo-make-hash (length overview)))))) + (while overview + ;; key is message-id + (if (caar overview) + (elmo-set-hash-val (caar overview) (car overview) hashtb)) + ;; key is number + (elmo-set-hash-val + (format "#%d" (elmo-msgdb-overview-entity-get-number (car overview))) + (car overview) hashtb) + (setq overview (cdr overview))) + hashtb) + (setq elmo-msgdb-overview-hashtb nil))) + +(defsubst elmo-msgdb-append (msgdb msgdb-append &optional set-hash) (list (nconc (car msgdb) (car msgdb-append)) (nconc (cadr msgdb) (cadr msgdb-append)) (nconc (caddr msgdb) (caddr msgdb-append)) - (nconc (cadddr msgdb) (cadddr msgdb-append)))) + (nconc (cadddr msgdb) (cadddr msgdb-append)) + (and set-hash + (elmo-msgdb-make-overview-hashtb (car msgdb-append) (nth 4 msgdb))))) + +(defsubst elmo-msgdb-clear (&optional msgdb) + (if msgdb + (list + (setcar msgdb nil) + (setcar (cdr msgdb) nil) + (setcar (cddr msgdb) nil) + (setcar (cdddr msgdb) nil) + (setcar (nthcdr 4 msgdb) (elmo-msgdb-make-overview-hashtb nil))) + (list nil nil nil nil (elmo-msgdb-make-overview-hashtb nil)))) (defun elmo-msgdb-delete-path (folder &optional spec) (let ((path (elmo-msgdb-expand-path folder spec))) diff --git a/elmo/elmo-util.el b/elmo/elmo-util.el index 923d479..28e5afe 100644 --- a/elmo/elmo-util.el +++ b/elmo/elmo-util.el @@ -1308,9 +1308,16 @@ Otherwise treat \\ in NEWTEXT string as special: (defmacro elmo-set-hash-val (string value hashtable) (list 'set (list 'intern string hashtable) value)) +(defmacro elmo-clear-hash-val (string hashtable) + (static-if (fboundp 'unintern) + (list 'unintern string hashtable) + (list 'makunbound (list 'intern string hashtable)))) + ;; Make a hash table (default and minimum size is 1024). (defun elmo-make-hash (&optional hashsize) - (make-vector (if hashsize (max (elmo-create-hash-size hashsize) 1024) 1024) 0)) + (make-vector + (if hashsize (max (min (elmo-create-hash-size hashsize) + elmo-hash-maximum-size) 1024) 1024) 0)) (defsubst elmo-mime-string (string) "Normalize MIME encoded string." diff --git a/elmo/elmo-vars.el b/elmo/elmo-vars.el index 950c2b5..11bc772 100644 --- a/elmo/elmo-vars.el +++ b/elmo/elmo-vars.el @@ -330,9 +330,15 @@ If function, return value of function.") If server doesn't accept asynchronous commands, this variable should be set as non-nil.") -(defvar elmo-use-decoded-cache t +(defvar elmo-hash-maximum-size 4096 + "Maximum size of hash table.") + +(defvar elmo-use-decoded-cache (featurep 'xemacs) "Use cache of decoded mime charset string.") +(defvar elmo-use-overview-hashtb t + "Use hash table of overview.") + (defvar elmo-display-progress-threshold 20 "*Displaying progress gauge if number of messages are more than this value.") diff --git a/elmo/elmo2.el b/elmo/elmo2.el index f191da3..fb8a118 100644 --- a/elmo/elmo2.el +++ b/elmo/elmo2.el @@ -209,9 +209,11 @@ without cacheing." (defun elmo-read-msg (folder msg outbuf msgdb &optional force-reload) "Read message into outbuf." (let ((inhibit-read-only t)) - (if (not (elmo-use-cache-p folder msg)) - (elmo-read-msg-no-cache folder msg outbuf) - (elmo-read-msg-with-cache folder msg outbuf msgdb force-reload)))) + ;;Only use elmo-read-msg-with-cache, because if folder is network and + ;;elmo-use-cache-p is nil, cannot read important msg. (by muse) + ;;(if (not (elmo-use-cache-p folder msg)) + ;; (elmo-read-msg-no-cache folder msg outbuf) + (elmo-read-msg-with-cache folder msg outbuf msgdb force-reload))) (defun elmo-read-msg-with-cache (folder msg outbuf msgdb &optional force-reload) @@ -235,7 +237,8 @@ without cacheing." (if (setq ret-val (elmo-call-func (car real-fld-num) "read-msg" (cdr real-fld-num) outbuf)) - (if (not (elmo-local-file-p folder msg)) + (if (and (not (elmo-local-file-p folder msg)) + (elmo-use-cache-p folder msg)) (elmo-cache-save message-id (elmo-string-partial-p ret-val) folder msg))) @@ -463,7 +466,9 @@ without cacheing." (list (elmo-msgdb-overview-load path) (elmo-msgdb-number-load path) (elmo-msgdb-mark-load path) - (elmo-msgdb-location-load path)))) + (elmo-msgdb-location-load path) + elmo-msgdb-overview-hashtb + ))) (message "Loading msgdb for %s...done." folder) (elmo-folder-set-info-max-by-numdb folder (nth 1 ret-val)) ret-val)) @@ -533,9 +538,10 @@ without cacheing." (elmo-msgdb-expand-path folder)))) (defun elmo-pack-number (folder msgdb arg) - (if (string-match "^[\\+=].*" folder) - (elmo-call-func folder "pack-number" msgdb arg) - (error "pack-number not supported"))) + (let ((type (elmo-folder-get-type folder))) + (if (memq type '(localdir localnews)) + (elmo-call-func folder "pack-number" msgdb arg) + (error "pack-number not supported")))) (defun elmo-sync-validity (folder) (elmo-call-func folder "sync-validity" -- 1.7.10.4