From b9e1b45232a7b8c73e8b726a8263225173626e05 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Sun, 29 May 2016 12:03:11 +0200 Subject: [PATCH] Hash all the record slots in vector-hash To: address@hidden Records are represented with tagged vectors and as such they are hashed by vector-hash that has a cutoff limit that's configurable using the *recursive-hash-max-length* parameter. Lift the restriction when the vector being hashed is a record so that all the slots are effectively hashed. --- srfi-69.scm | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/srfi-69.scm b/srfi-69.scm index bdc7f72..3594920 100644 --- a/srfi-69.scm +++ b/srfi-69.scm @@ -306,17 +306,20 @@ ; Recurse into some portion of the vector's slots (define (vector-hash obj seed depth start rnd) - (let ([len (##sys#size obj)]) - (let loop ([hsh (fx+ len (fxxor seed rnd))] - [i start] - [len (fx- (fxmax start (fxmin *recursive-hash-max-length* len)) start)] ) + (let* ((len (##sys#size obj)) + (struct? (##sys#generic-structure? obj)) + ; Make sure to hash all the slots when obj is a record + (max-length (if struct? len *recursive-hash-max-length*))) + (let loop ((hsh (fx+ len (fxxor seed rnd))) + (i start) + (len (fx- (fxmax start (fxmin max-length len)) start))) (if (fx= len 0) hsh (loop (fx+ hsh (fx+ (fxshl hsh 4) (recursive-hash (##sys#slot obj i) (fx+ depth 1) rnd))) (fx+ i 1) - (fx- len 1) ) ) ) ) ) + (fx- len 1)))))) ; Recurse into structured objects (define (recursive-hash obj depth rnd) -- 2.8.3