Skip to content

Commit 173e2ad

Browse files
committed
Reuse the same buffer when decoding bencode
Profiling shows that creating a new buffer each time is not free. It is also unnecessary. Reuse the same named buffer, clearing it each time.
1 parent 98013c8 commit 173e2ad

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

nrepl-client.el

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,9 @@ containing the remainder of the input strings which could not be
379379
decoded. RESPONSE-Q is the original queue with successfully decoded messages
380380
enqueued and with slot STUB containing a nested stack of an incompletely
381381
decoded message or nil if the strings were completely decoded."
382-
(with-temp-buffer
382+
(with-current-buffer (get-buffer-create " *nrepl-decoding*")
383+
(fundamental-mode)
384+
(erase-buffer)
383385
(if (queue-p string-q)
384386
(while (queue-head string-q)
385387
(insert (queue-dequeue string-q)))
@@ -400,6 +402,7 @@ decoded message or nil if the strings were completely decoded."
400402
(setf (nrepl-response-queue-stub response-q) (cdr istack))
401403
(queue-enqueue response-q (cadr istack))
402404
(setf (nrepl-response-queue-stub response-q) nil))
405+
(erase-buffer)
403406
(cons string-q response-q))))
404407

405408
(defun nrepl-bencode (object)

0 commit comments

Comments
 (0)