From aeed8b51d4c60fd015f5bc9e52b4e43953ebdb22 Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Thu, 6 Feb 2014 22:38:48 -0800 Subject: [PATCH] hash-sets: faster members. --- core/hash-sets/hash-sets.factor | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/core/hash-sets/hash-sets.factor b/core/hash-sets/hash-sets.factor index 178ccf11ea..3f98d7fdd7 100644 --- a/core/hash-sets/hash-sets.factor +++ b/core/hash-sets/hash-sets.factor @@ -1,9 +1,10 @@ ! Copyright (C) 2010 Daniel Ehrenberg ! Copyright (C) 2005, 2011 John Benediktsson, Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors arrays hash-sets hashtables.private kernel -kernel.private math math.private sequences sequences.private -sets sets.private slots.private vectors ; +USING: accessors arrays growable.private hash-sets +hashtables.private kernel kernel.private math math.private +sequences sequences.private sets sets.private slots.private +vectors ; IN: hash-sets TUPLE: hash-set @@ -71,7 +72,7 @@ TUPLE: hash-set [ count>> 3 fixnum*fast ] [ array>> length>> 1 fixnum-shift-fast ] bi fixnum>= ; inline -: each-member ( array quot: ( elt -- ) -- ) +: each-member ( ... array quot: ( ... elt -- ... ) -- ... ) [ if ] curry [ dup tombstone? [ drop ] ] prepose each ; inline : grow-hash ( hash -- ) @@ -116,9 +117,9 @@ M: hash-set ?adjoin dup ?grow-hash (adjoin) ; M: hash-set members - [ array>> ] [ cardinality ] bi [ - [ push-unsafe ] curry each-member - ] keep { } like ; + [ array>> 0 swap ] [ cardinality f ] bi [ + [ [ over ] dip set-nth-unsafe 1 + ] curry each-member + ] keep nip ; M: hash-set clone (clone) [ clone ] change-array ; inline