Skip to content

Commit 64e89ff

Browse files
committed
Fix slow verilog-auto expansion.
* verilog-mode.el (verilog-modi-lookup, verilog-modi-lookup-cache, verilog-modi-lookup-last-current, verilog-modi-lookup-last-mod, verilog-modi-lookup-last-modi, verilog-modi-lookup-last-tick): Fix slow verilog-auto expansion on very large files. (5th fix: Modi cache should preserve all sub-modules not just most recent.) git-svn-id: file:///verilog-mode-svn/trunk@599 db5bb42b-8904-0410-88e9-aa7026cf2ec3
1 parent 194e186 commit 64e89ff

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

verilog-mode.el

+22-17
Original file line numberDiff line numberDiff line change
@@ -8244,37 +8244,38 @@ Use `verilog-preserve-modi-cache' to set it.")
82448244
;; return
82458245
(vector name (or (buffer-file-name) (current-buffer)) pt)))
82468246

8247-
(defvar verilog-modi-lookup-last-mod nil "Cache of last module looked up.")
8248-
(defvar verilog-modi-lookup-last-modi nil "Cache of last modi returned.")
8249-
(defvar verilog-modi-lookup-last-current nil "Cache of last `current-buffer' looked up.")
8250-
(defvar verilog-modi-lookup-last-tick nil "Cache of last `buffer-modified-tick' looked up.")
8247+
(defvar verilog-modi-lookup-cache nil "Hash of (modulename modi).")
8248+
(defvar verilog-modi-lookup-last-current nil "Cache of `current-buffer' at last lookup.")
8249+
(defvar verilog-modi-lookup-last-tick nil "Cache of `buffer-modified-tick' at last lookup.")
82518250

82528251
(defun verilog-modi-lookup (module allow-cache &optional ignore-error)
82538252
"Find the file and point at which MODULE is defined.
82548253
If ALLOW-CACHE is set, check and remember cache of previous lookups.
82558254
Return modi if successful, else print message unless IGNORE-ERROR is true."
8256-
(let* ((current (or (buffer-file-name) (current-buffer))))
8257-
(cond ((and verilog-modi-lookup-last-modi
8255+
(let* ((current (or (buffer-file-name) (current-buffer)))
8256+
modi)
8257+
;; Check cache
8258+
;;(message "verilog-modi-lookup: %s" module)
8259+
(cond ((and verilog-modi-lookup-cache
82588260
verilog-cache-enabled
82598261
allow-cache
8260-
(equal verilog-modi-lookup-last-mod module)
8262+
(setq modi (gethash module verilog-modi-lookup-cache))
82618263
(equal verilog-modi-lookup-last-current current)
82628264
;; Iff hit is in current buffer, then tick must match
82638265
(or (equal verilog-modi-lookup-last-tick (buffer-modified-tick))
8264-
(not (equal current (verilog-modi-file-or-buffer
8265-
verilog-modi-lookup-last-modi)))))
8266-
;; ok as is
8267-
)
8266+
(not (equal current (verilog-modi-file-or-buffer modi)))))
8267+
;;(message "verilog-modi-lookup: HIT %S" modi)
8268+
modi)
8269+
;; Miss
82688270
(t (let* ((realmod (verilog-symbol-detick module t))
82698271
(orig-filenames (verilog-module-filenames realmod current))
82708272
(filenames orig-filenames)
82718273
pt)
82728274
(while (and filenames (not pt))
82738275
(if (not (setq pt (verilog-module-inside-filename-p realmod (car filenames))))
82748276
(setq filenames (cdr filenames))))
8275-
(cond (pt (setq verilog-modi-lookup-last-modi
8276-
(vector realmod (car filenames) pt)))
8277-
(t (setq verilog-modi-lookup-last-modi nil)
8277+
(cond (pt (setq modi (vector realmod (car filenames) pt)))
8278+
(t (setq modi nil)
82788279
(or ignore-error
82798280
(error (concat (verilog-point-text)
82808281
": Can't locate " module " module definition"
@@ -8284,10 +8285,14 @@ Return modi if successful, else print message unless IGNORE-ERROR is true."
82848285
"\n Check the verilog-library-directories variable."
82858286
"\n I looked in (if not listed, doesn't exist):\n\t"
82868287
(mapconcat 'concat orig-filenames "\n\t"))))))
8287-
(setq verilog-modi-lookup-last-mod module
8288-
verilog-modi-lookup-last-current current
8288+
(when (eval-when-compile (fboundp 'make-hash-table))
8289+
(unless verilog-modi-lookup-cache
8290+
(setq verilog-modi-lookup-cache
8291+
(make-hash-table :test 'equal :rehash-size 4.0)))
8292+
(puthash module modi verilog-modi-lookup-cache))
8293+
(setq verilog-modi-lookup-last-current current
82898294
verilog-modi-lookup-last-tick (buffer-modified-tick)))))
8290-
verilog-modi-lookup-last-modi))
8295+
modi))
82918296

82928297
(defsubst verilog-modi-name (modi)
82938298
(aref modi 0))

0 commit comments

Comments
 (0)