X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcode%2Ftarget-sxhash.lisp;h=38422a105c00dfdd61d212faa698565b51faf52c;hb=15d6e7c9a2c3234f95dfe278046fa2fee1b0c007;hp=99e0830773f2a122a16aa0f5d947ce999e36a60e;hpb=aa15be083d706358ce3611e750b95b7abcde6d61;p=sbcl.git diff --git a/src/code/target-sxhash.lisp b/src/code/target-sxhash.lisp index 99e0830..38422a1 100644 --- a/src/code/target-sxhash.lisp +++ b/src/code/target-sxhash.lisp @@ -36,9 +36,10 @@ ;;; * We'd like this to be simple and fast, too. ;;; ;;; FIXME: Should this be INLINE? -(declaim (ftype (function ((and fixnum unsigned-byte) - (and fixnum unsigned-byte)) - (and fixnum unsigned-byte)) mix)) +(declaim (ftype (sfunction ((and fixnum unsigned-byte) + (and fixnum unsigned-byte)) + (and fixnum unsigned-byte)) + mix)) (defun mix (x y) ;; FIXME: We wouldn't need the nasty (SAFETY 0) here if the compiler ;; were smarter about optimizing ASH. (Without the THE FIXNUM below, @@ -89,7 +90,7 @@ (declare (type string string)) (declare (type index count)) (let ((result 0)) - (declare (type (unsigned-byte 32) result)) + (declare (type (unsigned-byte 32) result)) (unless (typep string '(vector nil)) (dotimes (i count) (declare (type index i)) @@ -144,6 +145,12 @@ ;;;; the SXHASH function +;; simple cases +(declaim (ftype (sfunction (integer) (integer 0 #.sb!xc:most-positive-fixnum)) + sxhash-bignum)) +(declaim (ftype (sfunction (t) (integer 0 #.sb!xc:most-positive-fixnum)) + sxhash-instance)) + (defun sxhash (x) ;; profiling SXHASH is hard, but we might as well try to make it go ;; fast, in case it is the bottleneck somwhere. -- CSR, 2003-03-14 @@ -168,11 +175,19 @@ (sxhash-recurse (x &optional (depthoid +max-hash-depthoid+)) (declare (type index depthoid)) (typecase x - (cons - (if (plusp depthoid) - (mix (sxhash-recurse (car x) (1- depthoid)) - (sxhash-recurse (cdr x) (1- depthoid))) - 261835505)) + ;; we test for LIST here, rather than CONS, because the + ;; type test for CONS is in fact the test for + ;; LIST-POINTER-LOWTAG followed by a negated test for + ;; NIL. If we're going to have to test for NIL anyway, + ;; we might as well do it explicitly and pick off the + ;; answer. -- CSR, 2004-07-14 + (list + (if (null x) + (sxhash x) ; through DEFTRANSFORM + (if (plusp depthoid) + (mix (sxhash-recurse (car x) (1- depthoid)) + (sxhash-recurse (cdr x) (1- depthoid))) + 261835505))) (instance (if (or (typep x 'structure-object) (typep x 'condition)) (logxor 422371266