Opened 7 years ago

Closed 7 years ago

#1064 closed enhancement (fixed)

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 (1)

comment:1 Changed 7 years ago by brooks

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

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.