[test-extras] rewrite strip-string to avoid repeat string-append

this is marginally more efficient, by keeping a list of (shared)
substrings, and only concatenating them when returning the stripped
string.
This commit is contained in:
Christopher Lam 2019-09-08 18:54:06 +08:00
parent b05c57a948
commit ff8c5725cd

View File

@ -61,14 +61,14 @@
render))) render)))
(define (strip-string s1 s2) (define (strip-string s1 s2)
(let loop ((str s1)) (let loop ((str s1)
(res '()))
(let ((startpos (string-contains str (format #f "<~a" s2))) (let ((startpos (string-contains str (format #f "<~a" s2)))
(endpos (string-contains str (format #f "</~a>" s2)))) (endpos (string-contains str (format #f "</~a>" s2))))
(if (and startpos endpos) (if (and startpos endpos)
(loop (string-append (loop (substring str (+ endpos (string-length s2) 3))
(string-take str startpos) (cons (substring str 0 startpos) res))
(string-drop str (+ endpos (string-length s2) 3)))) (string-concatenate-reverse (cons str res))))))
str))))
(export gnc:options->sxml) (export gnc:options->sxml)
(define* (gnc:options->sxml uuid options prefix test-title #:key strip-tag) (define* (gnc:options->sxml uuid options prefix test-title #:key strip-tag)