From: Christophe Rhodes Date: Sat, 25 Oct 2014 21:28:33 +0000 (+0100) Subject: much better `squeeze-unhex-and-decode-utf8-string' X-Git-Url: http://christophe.rhodes.io/gitweb/?p=squeeze-el.git;a=commitdiff_plain;h=0e4ee58cdc46656c8ffaa2e9e0b642c88036b980 much better `squeeze-unhex-and-decode-utf8-string' It turns out that `url-unhex-string' uses the multiple-concat strategy that I just removed from `squeeze-update-state', which ends up scaling quadratically in the size of the input. This is bad, particularly when we are working (as I am) with large output string such as resulting from an albums query. --- diff --git a/squeeze.el b/squeeze.el index 977813b..2549159 100644 --- a/squeeze.el +++ b/squeeze.el @@ -15,8 +15,23 @@ (define-key map (kbd "TAB") 'completion-at-point) map)) +(defun squeeze-unhex-string (string) + (with-temp-buffer + (let ((case-fold-search t) + (start 0)) + (while (string-match "%[0-9a-f][0-9a-f]" string start) + (let* ((s (match-beginning 0)) + (ch1 (url-unhex (elt string (+ s 1)))) + (code (+ (* 16 ch1) + (url-unhex (elt string (+ s 2)))))) + (insert (substring string start s) + (byte-to-string code)) + (setq start (match-end 0)))) + (insert (substring string start))) + (buffer-string))) + (defun squeeze-unhex-and-decode-utf8-string (string) - (decode-coding-string (url-unhex-string string) 'utf-8)) + (decode-coding-string (squeeze-unhex-string string) 'utf-8)) (define-derived-mode squeeze-mode comint-mode "Squeeze" "Major mode for interacting with the Squeezebox Server CLI.\\"