mirror of
https://github.com/Gnucash/gnucash.git
synced 2024-11-28 03:34:05 -06:00
7d15e6e4e7
copied function created by Mark Weaver, core guile dev and augmented to selectively replace substring indices This is a much more efficient function than the previous gnc:substring-replace which will constantly split lists using substring, and create new strings using string-append. It also does tail call optimization properly, unlike the previous functions. https://lists.gnu.org/archive/html/guile-devel/2013-09/msg00029.html - original "Here's an implementation that does this benchmark about 80 times faster on my machine: (20 milliseconds vs 1.69 seconds) --8<---------------cut here---------------start------------->8--- (define* (string-replace-substring s substr replacement #:optional (start 0) (end (string-length s))) (let ((substr-length (string-length substr))) (if (zero? substr-length) (error "string-replace-substring: empty substr") (let loop ((start start) (pieces (list (substring s 0 start)))) (let ((idx (string-contains s substr start end))) (if idx (loop (+ idx substr-length) (cons* replacement (substring s start idx) pieces)) (string-concatenate-reverse (cons (substring s start) pieces)))))))) --8<---------------cut here---------------end--------------->8--- The reason this is so much faster is because it avoids needless generation of intermediate strings." |
||
---|---|---|
.. | ||
test | ||
CMakeLists.txt | ||
price-quotes.scm | ||
utilities.scm |