Ticket #1064 (closed enhancement: fixed)

Opened 19 months ago

Last modified 19 months ago

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 ,state 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

comment:1 Changed 19 months ago by brooks

  • Status changed from new to closed
  • Resolution set to fixed

Sorry, typo -- should have been ",values", not ,state. Further clumsiness led to me reporting the correct version as #1065. Therefore I will mark this one (#1064) as resolved and leave you with #1065. My apologies.

Note: See TracTickets for help on using tickets.