]> rhodes.io Git - squeeze-el.git/commitdiff
Christophe Weblog Wiki Code Publications Music
slightly better `squeeze-update-state'
authorChristophe Rhodes <csr21@cantab.net>
Sat, 25 Oct 2014 21:26:31 +0000 (22:26 +0100)
committerChristophe Rhodes <csr21@cantab.net>
Sat, 25 Oct 2014 21:26:31 +0000 (22:26 +0100)
use a temporary buffer rather than multiple calls to `concat'

squeeze.el

index dbab10e9df862cbaa72e2e96d3785c7df157d7b8..977813b28fc24c118fc0dafd600d7c7901250723 100644 (file)
 
 (defvar squeeze-control-inhibit-display nil)
 
-(lexical-let ((buffer ""))
+(lexical-let ((buffer (get-buffer-create " *squeeze-update-state*")))
   (defun squeeze-update-state (string)
+    ;; FIXME: we could make this a lot more elegant by using the
+    ;; buffer abstraction more
     (if (cl-position ?\n string)
         (let (done-something)
-          (setq string (concat buffer string))
+          (with-current-buffer buffer
+            (insert string)
+            (setq string (buffer-string))
+            (erase-buffer))
           (dolist (line (split-string string "\n"))
             (when (squeeze-update-state-from-line line)
               (setq done-something t)))
           (when done-something
             (unless squeeze-control-inhibit-display
-              (squeeze-control-display-players)))
-          (setq buffer ""))
-      (setq buffer (concat buffer string)))
+              (squeeze-control-display-players))))
+      (with-current-buffer buffer
+        (insert string)))
     string))
 
 (defconst squeeze-player-line-regexp