diff options
| author | Andreas Politz <politza@hochschule-trier.de> | 2019-01-18 20:16:30 +0100 |
|---|---|---|
| committer | Andreas Politz <politza@hochschule-trier.de> | 2019-01-18 20:16:30 +0100 |
| commit | 0869ccc03c30fcc779c881d695851607a3fa60d0 (patch) | |
| tree | 4571e61eef42138419fd0f59d5fbfff1dca6e225 | |
| parent | b03449b7c3a64ad0e3eaba5b847474fc456a6326 (diff) | |
| parent | 35931ad415adcb0085c6e8cdf52d3988311c3d9b (diff) | |
Merge branch 'dzop/cache-edge-case'
| -rw-r--r-- | lisp/pdf-cache.el | 19 | ||||
| -rw-r--r-- | test/pdf-cache-test.el | 31 |
2 files changed, 38 insertions, 12 deletions
diff --git a/lisp/pdf-cache.el b/lisp/pdf-cache.el index 49b86d7..ea4182f 100644 --- a/lisp/pdf-cache.el +++ b/lisp/pdf-cache.el @@ -207,21 +207,16 @@ width MAX-WIDTH and `eql' hash value. Remember that image was recently used. Returns nil, if no matching image was found." - (let ((cache (cons nil pdf-cache--image-cache)) + (let ((cache pdf-cache--image-cache) image) - ;; Find it in the cache and remove it. We need to find the - ;; element in front of it. - (while (and (cdr cache) + ;; Find it in the cache. + (while (and (setq image (pop cache)) (not (pdf-cache--image-match - (car (cdr cache)) - page min-width max-width hash))) - (setq cache (cdr cache))) - (setq image (cadr cache)) - (when (car cache) - (setcdr cache (cddr cache))) - ;; Now push it at the front. + image page min-width max-width hash)))) + ;; Remove it and push it to the front. (when image - (push image pdf-cache--image-cache) + (setq pdf-cache--image-cache + (cons image (delq image pdf-cache--image-cache))) (pdf-cache--image/data image)))) (defun pdf-cache-put-image (page width data &optional hash) diff --git a/test/pdf-cache-test.el b/test/pdf-cache-test.el new file mode 100644 index 0000000..26b7fe7 --- /dev/null +++ b/test/pdf-cache-test.el @@ -0,0 +1,31 @@ + + +;; * ================================================================== * +;; * Tests for pdf-cache.el +;; * ================================================================== * + +(require 'pdf-cache) +(require 'ert) + +(ert-deftest pdf-cache-get-image () + (let (pdf-cache--image-cache) + (should-not (pdf-cache-get-image 1 1)) + (setq pdf-cache--image-cache + (list + (pdf-cache--make-image 1 1 "1" nil) + (pdf-cache--make-image 2 1 "2" nil) + (pdf-cache--make-image 3 1 "3" nil))) + (should (equal (pdf-cache-get-image 1 1) "1")) + (should (equal pdf-cache--image-cache + (list + (pdf-cache--make-image 1 1 "1" nil) + (pdf-cache--make-image 2 1 "2" nil) + (pdf-cache--make-image 3 1 "3" nil)))) + (should (equal (pdf-cache-get-image 2 1) "2")) + (should (equal pdf-cache--image-cache + (list + (pdf-cache--make-image 2 1 "2" nil) + (pdf-cache--make-image 1 1 "1" nil) + (pdf-cache--make-image 3 1 "3" nil)))) + (should-not (pdf-cache-get-image 4 1)))) + |
