summary refs log tree commit diff
path: root/src/guile
diff options
context:
space:
mode:
authorLudovic Courtes2006-02-27 00:46:25 +0000
committerLudovic Courtes2006-02-27 00:46:25 +0000
commitb545d9c6e347dfc8c7e3fa0c7cd3c90485644240 (patch)
tree08bc6c0701a8a00cf260928bd719c306b4ed9b67 /src/guile
parent716e3a477583ff7680b5188a60395fd2e4b150c3 (diff)
parenta0d8397787ffcaaec7c885542fb5e7f3de3fdc9a (diff)
downloadskribilo-b545d9c6e347dfc8c7e3fa0c7cd3c90485644240.tar.gz
skribilo-b545d9c6e347dfc8c7e3fa0c7cd3c90485644240.tar.lz
skribilo-b545d9c6e347dfc8c7e3fa0c7cd3c90485644240.zip
Made `make-string-replace' faster.
Patches applied:

 * skribilo--devel--1.2  (patch 34-35)

   - Merge from lcourtes@laas.fr--2004-libre
   - Made `make-string-replace' faster.

git-archimport-id: lcourtes@laas.fr--2004-libre/skribilo--devel--1.2--patch-55
Diffstat (limited to 'src/guile')
-rw-r--r--src/guile/skribilo/runtime.scm24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/guile/skribilo/runtime.scm b/src/guile/skribilo/runtime.scm
index bd8497f..da5c525 100644
--- a/src/guile/skribilo/runtime.scm
+++ b/src/guile/skribilo/runtime.scm
@@ -180,13 +180,23 @@
 
 (define (%make-general-string-replace lst)
   ;; The general version
-  (lambda (str)
-    (let ((out (open-output-string)))
-      (string-for-each (lambda (ch)
-			 (let ((res (assq ch lst)))
-			   (display (if res (cadr res) ch) out)))
-		       str)
-      (get-output-string out))))
+  (let ((chars (make-hash-table)))
+
+    ;; Setup a hash table equivalent to LST.
+    (for-each (lambda (chr)
+		(hashq-set! chars (car chr) (cadr chr)))
+	      lst)
+
+    ;; Help the GC.
+    (set! lst #f)
+
+    (lambda (str)
+      (let ((out (open-output-string)))
+	(string-for-each (lambda (ch)
+			   (let ((res (hashq-ref chars ch #f)))
+			     (display (if res res ch) out)))
+			 str)
+	(get-output-string out)))))
 
 (define string->html
   (%make-general-string-replace '((#\" "&quot;") (#\& "&amp;") (#\< "&lt;")