Opened 7 years ago

#1065 new enhancement

reduce maphash consing

Reported by: brooks Owned by:
Priority: normal Milestone:
Component: Performance Version: trunk
Keywords: Cc:


with-hash-table-iterator in file macros.lisp results in what appears to be unnecessary consing.

Consing is reduced by adding ,values to the list of dynamic-extent declarations, as shown below.

(defmacro with-hash-table-iterator ((mname hash-table) &body body)

"WITH-HASH-TABLE-ITERATOR ((function hash-table) &body body)

provides a method of manually looping over the elements of a hash-table. FUNCTION is bound to a generator-macro that, within the scope of the invocation, returns one or three values. The first value tells whether any objects remain in the hash table. When the first value is non-NIL, the second and third values are the key and the value of the next object."

(let* ((hash (gensym))

(keys (gensym)) (values (gensym)) (count (gensym)) (state (gensym)))

`(let* ((,hash ,hash-table)

(,count (hash-table-count ,hash)) (,keys (make-array ,count)) (,values (make-array ,count)) (,state (vector ,hash 0 ,keys ,values (enumerate-hash-keys-and-values ,hash ,keys ,values))))

(declare (dynamic-extent ,keys ,values ,state)

(fixnum ,count))

(macrolet ((,mname () `(next-hash-table-iteration-1 ,',state)))


Change History (0)

Note: See TracTickets for help on using tickets.