about summary refs log tree commit diff
path: root/users/sterni
diff options
context:
space:
mode:
authorsterni <sternenseemann@systemli.org>2022-02-01T15·33+0100
committersterni <sternenseemann@systemli.org>2022-02-02T20·47+0000
commit81c47da91c90fd8bac96c6088112f71a11964131 (patch)
tree2ce4473c4141161ef5f395ba9e951cd66ed4852e /users/sterni
parent98e4cd032f45ade1c408162ebccd914f31266f9f (diff)
refactor(sterni/mblog/note): don't escape streams char by char r/3753
Depending on the stream backing this, read-sequence should be more
efficient.

Change-Id: I5d0461f76f4b132ac6e6c3a2e503f0173d5f4114
Reviewed-on: https://cl.tvl.fyi/c/depot/+/5194
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
Diffstat (limited to 'users/sterni')
-rw-r--r--users/sterni/mblog/note.lisp12
-rw-r--r--users/sterni/mblog/packages.lisp2
2 files changed, 9 insertions, 5 deletions
diff --git a/users/sterni/mblog/note.lisp b/users/sterni/mblog/note.lisp
index b1f903c9a7aa..f953d6b1e662 100644
--- a/users/sterni/mblog/note.lisp
+++ b/users/sterni/mblog/note.lisp
@@ -3,12 +3,16 @@
 
 ;;; util
 
+;; TODO(sterni): merge this with mblog::*copy-buffer-size*
+(defvar *copy-buffer-size* 4096)
+
 (defun html-escape-stream (in out)
   "Escape characters read from stream IN and write them to
-  stream OUT escaped using WHO:ESCAPE-CHAR-MINIMAL."
-  (loop for char = (read-char in nil nil)
-        while char
-        do (write-string (who:escape-char-minimal char) out)))
+  stream OUT escaped using WHO:ESCAPE-STRING-MINIMAL."
+  (let ((buf (make-string *copy-buffer-size*)))
+    (loop for len = (read-sequence buf in)
+          while (> len 0)
+          do (write-string (who:escape-string-minimal (subseq buf 0 len)) out))))
 
 (defun cid-header-value (cid)
   "Takes a Content-ID as present in Apple Notes' <object> tags and properly
diff --git a/users/sterni/mblog/packages.lisp b/users/sterni/mblog/packages.lisp
index 651dc6f2618d..94fce16d40cf 100644
--- a/users/sterni/mblog/packages.lisp
+++ b/users/sterni/mblog/packages.lisp
@@ -19,7 +19,7 @@
    :when-let
    :starts-with-subseq
    :ends-with-subseq)
-  (:import-from :who :escape-char-minimal)
+  (:import-from :who :escape-string-minimal)
   (:export
    :apple-note
    :apple-note-uuid