Skip to content

Commit 717c81e

Browse files
authored
Make popup-replace-displayable much faster
One of my users reported a performance bug, which I tracked down to `popup-replace-displayable` (gcv/julia-snail#110). Calling `popup-replace-displayable` takes ~3 seconds on a string of about 8000 characters on my system, and becomes much slower on larger inputs. The attached PR eliminates the large number of string concatenations and significantly improves the function's performance.
1 parent c303445 commit 717c81e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

popup.el

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,15 +244,15 @@ ITEM is not string."
244244
245245
Optional argument REP is the replacement string of
246246
non-displayable character."
247-
(unless rep (setq rep ""))
248-
(let ((result ""))
247+
(let ((rep (or rep ""))
248+
(results (list)))
249249
(dolist (string (split-string str ""))
250250
(let* ((char (string-to-char string))
251251
(string (if (char-displayable-p char)
252252
string
253253
rep)))
254-
(setq result (concat result string))))
255-
result))
254+
(push string results)))
255+
(string-join (reverse results))))
256256

257257
(cl-defun popup-make-item (name
258258
&key

0 commit comments

Comments
 (0)