From e1c2b781af8e10e078ab95920ce0208eb9f5e6bf Mon Sep 17 00:00:00 2001 From: "Kevin M. Rosenberg" Date: Wed, 29 Oct 2003 02:38:46 +0000 Subject: [PATCH] r8073: add def-cached-vector --- color.lisp | 22 ++++++++++++++++------ macros.lisp | 28 ++++++++++++++++++++++++++++ package.lisp | 1 + 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/color.lisp b/color.lisp index 11f809e..d674886 100644 --- a/color.lisp +++ b/color.lisp @@ -268,7 +268,7 @@ (when (<= (abs (- v1 v2)) value-range) t)) (t - (when (and (<= (hue-difference-fixnum h1 h2) hue-range) + (when (and (<= (abs (hue-difference-fixnum h1 h2)) hue-range) (<= (abs (- v1 v2)) value-range) (<= (abs (- s1 s2)) saturation-range)) t)))) @@ -277,7 +277,12 @@ (defun hue-difference (h1 h2) "Return difference between two hues around 360 degree circle" - (when (and h1 h2) + (cond + ((and (null h1) (null h2)) + t) + ((or (null h1) (null h2)) + 360) + (t (let ((diff (- h2 h1))) (cond ((< diff -180) @@ -286,12 +291,17 @@ ((> diff 180) (- (- 360 diff))) (t - diff))))) + diff)))))) (defun hue-difference-fixnum (h1 h2) "Return difference between two hues around 360 degree circle" - (when (and h1 h2) + (cond + ((and (null h1) (null h2)) + t) + ((or (null h1) (null h2)) + 360) + (t (locally (declare (type fixnum h1 h2)) (let ((diff (- h2 h1))) (cond @@ -301,5 +311,5 @@ ((> diff 180) (- (- 360 diff))) (t - diff)))))) - \ No newline at end of file + diff))))))) + diff --git a/macros.lisp b/macros.lisp index 835c6d9..5b72865 100644 --- a/macros.lisp +++ b/macros.lisp @@ -187,3 +187,31 @@ ,@(when docp `((setf (documentation ',var 'variable) ,doc))) (define-symbol-macro ,var ,backing-var)))) + +(defmacro def-cached-vector (name element-type) + (let ((get-name (concat-symbol "get-" name "-vector")) + (release-name (concat-symbol "release-" name "-vector")) + (table-name (concat-symbol "*cached-" name "-table*")) + (lock-name (concat-symbol "*cached-" name "-lock*"))) + `(eval-when (:compile-toplevel :load-toplevel :execute) + (defvar ,table-name (make-hash-table :test 'equal)) + (defvar ,lock-name (kmrcl::make-lock ,name)) + + (defun ,get-name (size) + (kmrcl::with-lock-held (,lock-name) + (let ((buffers (gethash (cons size ,element-type) ,table-name))) + (if buffers + (let ((buffer (pop buffers))) + (setf (gethash (cons size ,element-type) ,table-name) buffers) + buffer) + (make-array size :element-type ,element-type))))) + + (defun ,release-name (buffer) + (kmrcl::with-lock-held (,lock-name) + (let ((buffers (gethash (cons (array-total-size buffer) + ,element-type) + ,table-name))) + (setf (gethash (cons (array-total-size buffer) + ,element-type) ,table-name) + (cons buffer buffers)))))))) + diff --git a/package.lisp b/package.lisp index 2edc6da..dd95e3c 100644 --- a/package.lisp +++ b/package.lisp @@ -131,6 +131,7 @@ #:mac #:mv-bind #:deflex + #:def-cached-vector ;; files.lisp #:print-file-contents -- 2.34.1