Remove redundant stack shuffling from hashtable implementation
parent
0183a40717
commit
849c83247d
|
@ -70,7 +70,7 @@ HELP: nth-pair
|
||||||
{ nth-pair set-nth-pair } related-words
|
{ nth-pair set-nth-pair } related-words
|
||||||
|
|
||||||
HELP: set-nth-pair
|
HELP: set-nth-pair
|
||||||
{ $values { "value" "the second element of the pair" } { "key" "the first element of the pair" } { "n" "an index in the sequence" } { "seq" "a sequence" } }
|
{ $values { "value" "the second element of the pair" } { "key" "the first element of the pair" } { "seq" "a sequence" } { "n" "an index in the sequence" } }
|
||||||
{ $description "Stores a pair of values into the elements with index " { $snippet "n" } " and " { $snippet "n+1" } ", respectively." }
|
{ $description "Stores a pair of values into the elements with index " { $snippet "n" } " and " { $snippet "n+1" } ", respectively." }
|
||||||
{ $warning "This word is in the " { $vocab-link "hashtables.private" } " vocabulary because it does not perform bounds checks." }
|
{ $warning "This word is in the " { $vocab-link "hashtables.private" } " vocabulary because it does not perform bounds checks." }
|
||||||
{ $side-effects "seq" } ;
|
{ $side-effects "seq" } ;
|
||||||
|
|
|
@ -59,8 +59,7 @@ IN: hashtables
|
||||||
swap 2 fixnum+fast 2dup slot -rot 1 fixnum+fast slot ;
|
swap 2 fixnum+fast 2dup slot -rot 1 fixnum+fast slot ;
|
||||||
inline
|
inline
|
||||||
|
|
||||||
: set-nth-pair ( value key n seq -- )
|
: set-nth-pair ( value key seq n -- )
|
||||||
swap
|
|
||||||
2 fixnum+fast [ set-slot ] 2keep
|
2 fixnum+fast [ set-slot ] 2keep
|
||||||
1 fixnum+fast set-slot ; inline
|
1 fixnum+fast set-slot ; inline
|
||||||
|
|
||||||
|
@ -73,7 +72,7 @@ IN: hashtables
|
||||||
: (set-hash) ( value key hash -- )
|
: (set-hash) ( value key hash -- )
|
||||||
2dup new-key@
|
2dup new-key@
|
||||||
[ rot hash-count+ ] [ rot drop ] if
|
[ rot hash-count+ ] [ rot drop ] if
|
||||||
swap set-nth-pair ; inline
|
set-nth-pair ; inline
|
||||||
|
|
||||||
: find-pair-next >r 2 fixnum+fast r> ; inline
|
: find-pair-next >r 2 fixnum+fast r> ; inline
|
||||||
|
|
||||||
|
@ -133,7 +132,7 @@ M: hashtable clear-assoc ( hash -- )
|
||||||
|
|
||||||
M: hashtable delete-at ( key hash -- )
|
M: hashtable delete-at ( key hash -- )
|
||||||
tuck key@ [
|
tuck key@ [
|
||||||
>r >r ((tombstone)) dup r> r> swap set-nth-pair
|
>r >r ((tombstone)) dup r> r> set-nth-pair
|
||||||
hash-deleted+
|
hash-deleted+
|
||||||
] [
|
] [
|
||||||
3drop
|
3drop
|
||||||
|
|
Loading…
Reference in New Issue