Faster M: hashtable >alist performs less dispatch and allocates less junk

db4
Slava Pestov 2008-11-11 23:03:50 -06:00
parent fab60f94a7
commit ed3a81a503
8 changed files with 11 additions and 4 deletions

View File

@ -119,7 +119,7 @@ t compile-dependencies? set-global
H{ } clone compiled set H{ } clone compiled set
[ queue-compile ] each [ queue-compile ] each
compile-queue get compile-loop compile-queue get compile-loop
compiled get >alist compiled get >alist >array
] with-scope ; ] with-scope ;
: enable-compiler ( -- ) : enable-compiler ( -- )

View File

@ -1,7 +1,7 @@
! Copyright (C) 2005, 2008 Slava Pestov. ! Copyright (C) 2005, 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays kernel kernel.private slots.private math USING: accessors arrays kernel kernel.private slots.private math
assocs math.private sequences sequences.private vectors grouping ; assocs math.private sequences sequences.private vectors ;
IN: hashtables IN: hashtables
TUPLE: hashtable TUPLE: hashtable
@ -129,14 +129,21 @@ M: hashtable set-at ( value key hash -- )
2 <hashtable> [ set-at ] keep ; 2 <hashtable> [ set-at ] keep ;
M: hashtable >alist M: hashtable >alist
array>> 2 <groups> [ first tombstone? not ] filter ; array>> [ length 2/ ] keep V{ } clone [
[
>r
>r 1 fixnum-shift-fast r>
[ array-nth ] [ >r 1 fixnum+fast r> array-nth ] 2bi r>
pick tombstone? [ 3drop ] [ [ 2array ] dip push ] if
] 2curry each
] keep ;
M: hashtable clone M: hashtable clone
(clone) [ clone ] change-array ; (clone) [ clone ] change-array ;
M: hashtable equal? M: hashtable equal?
over hashtable? [ over hashtable? [
2dup [ assoc-size ] bi@ number= 2dup [ assoc-size ] bi@ eq?
[ assoc= ] [ 2drop f ] if [ assoc= ] [ 2drop f ] if
] [ 2drop f ] if ; ] [ 2drop f ] if ;