Skip to content

Commit 68ac1f1

Browse files
committed
[optim] slightly speedup pygc
1 parent 69a25cf commit 68ac1f1

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/gil-gc.lisp

+16-16
Original file line numberDiff line numberDiff line change
@@ -194,22 +194,22 @@ This avoids inadvertent calls to DecRef during recursions.")
194194
;; :do (let ((ptr (make-pointer addr)))
195195
;; (format t "~%At ~A with refcnt ~A:~% ~A"
196196
;; ptr count (lispify ptr))))
197-
(maphash (lambda (addr count)
198-
(declare (type #+64-bit (unsigned-byte 64)
199-
#-64-bit unsigned-byte
200-
addr)
201-
(type fixnum count))
202-
(when (and addr (not (zerop addr)))
203-
(with-python-gil/no-errors
204-
(cond ((< count 0)
205-
(foreign-funcall "Py_IncRef" :unsigned-long addr))
206-
((> count 0)
207-
(foreign-funcall "Py_DecRef" :unsigned-long addr))))))
208-
ht)
209-
(maphash (lambda (addr count)
210-
(declare (ignore count))
211-
(remhash addr ht))
212-
ht))
197+
(with-python-gil/no-errors
198+
(with-hash-table-iterator (ht-iter ht)
199+
(loop :do (multiple-value-bind (validp addr count) (ht-iter)
200+
(unless validp (return))
201+
(locally (declare (type #+64-bit (unsigned-byte 64)
202+
#-64-bit unsigned-byte
203+
addr)
204+
(type fixnum count))
205+
(when (not (zerop addr))
206+
(cond ((< count 0)
207+
(foreign-funcall "Py_IncRef"
208+
:unsigned-long addr))
209+
((> count 0)
210+
(foreign-funcall "Py_DecRef"
211+
:unsigned-long addr))))
212+
(remhash addr ht)))))))
213213
(clear-lisp-objects))
214214
nil)
215215

0 commit comments

Comments
 (0)