unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Arne Babenhauserheide <arne_bab@web.de>
To: guile-devel@gnu.org
Subject: Re: [PATCH] Add string-replace-substring to (ice-9 string-fun)
Date: Sun, 05 Jan 2020 16:49:26 +0100	[thread overview]
Message-ID: <871rsdgayh.fsf@web.de> (raw)
In-Reply-To: <CAKVAZZ+ggRp1XNP23rvCCeioCRWRUk32Oigns4uhHSfw6+74kA@mail.gmail.com>


Christopher Lam <christopher.lck@gmail.com> writes:

> This function has an interesting history.
>
> Someone or something in #guile had clued me there was a magic
> string-replace-substring somewhere in guile-user archives. With some luck I
> found it, and had bookmarked it, and kept it at the back of my mind for a
> good number of months.

To take the history further: I had initially started a very slow version
of string-replace-substring for wisp (because in the original wisp
parser which re-implemented something like read I needed
string-replacing all the time):
https://lists.gnu.org/archive/html/guile-devel/2013-09/msg00028.html

The original version looked like this (written on the Friday 13th in
September 2013):
define : string-replace-substring s substring replacement
       . "Replace every instance of substring in s by replacement."
       let : : sublen : string-length substring
           let replacer
               : newstring s
                 index : string-contains s substring
               if : not : equal? index #f
                  let : : replaced : string-replace s replacement index : + index sublen
                    replacer replaced : string-contains replaced substring
                  . newstring

;; ^
;; |
;; +---- horribly slow code! Do not copy!

It was afterwards improved with help by ijp to be 2x faster, and then by
Mark Weaver to be 80x faster (that’s not a typo: 80x faster!).

Half a year later Andy Wingo improved it further, replacing define* by
define, but I did not use it back then, because I needed full utf8 at
all times, regardless of the port encoding.

So the current version is at least 160x faster than my initial naive
implementation.

Thank you very much for picking it up and getting it into Guile!

Best wishes,
Arne
--
Unpolitisch sein
heißt politisch sein
ohne es zu merken



  reply	other threads:[~2020-01-05 15:49 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-20 17:32 [PATCH] Add string-replace-substring to (ice-9 string-fun) lloda
2020-01-05 11:34 ` Andy Wingo
2020-01-05 12:12   ` Jan Nieuwenhuizen
2020-01-05 13:51     ` Christopher Lam
2020-01-05 15:49       ` Arne Babenhauserheide [this message]
2020-01-05 14:01     ` lloda
2020-01-05 23:40       ` David Pirotte
2020-01-06  9:08 ` Linus Björnstam

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871rsdgayh.fsf@web.de \
    --to=arne_bab@web.de \
    --cc=guile-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).