unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* string-delete consing
@ 2005-06-05  1:37 Kevin Ryde
  2005-06-10 22:41 ` Kevin Ryde
  0 siblings, 1 reply; 3+ messages in thread
From: Kevin Ryde @ 2005-06-05  1:37 UTC (permalink / raw)


string-delete looks like it throws off a fair bit of garbage, a cons
cell for every character in the output string.

I'm thinking of the following for the "char" and "charset" deleting
cases.  Count what will be kept then copy to a destination string.

I'm not quite sure about the scm_i_string_chars though.  The idea is
to call that again after anything that might gc, is it?


    if (SCM_CHARP (char_pred))
      {
        char chr, *dst;
        size_t count;

        chr = SCM_CHAR (char_pred);

        /* count how many chars to keep */
        count = 0;
        for (idx = cstart; idx < cend; idx++)
          if (cstr[idx] != chr)
            count++;

        /* new string for them (and cstr again in case gc moves it) */
        newstr = scm_i_make_string (count, &dst);
        cstr = scm_i_string_chars (s);

        /* decrement "count" in this loop as well as using idx, so that if
           another thread is simultaneously changing the input str we
           won't go past the end of newstr */
        for (idx = cstart; idx < cend && count != 0; idx++, count--)
          {
            if (cstr[idx] != chr)
              *dst++ = cstr[idx];
          }
        result = newstr;
      }

For the "procedure" case, I'm thinking of mallocing a block to keep
the characters the procedure says to keep.  That block would start out
as the size of the input, then be realloced down when the true size is
known.


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: string-delete consing
  2005-06-05  1:37 string-delete consing Kevin Ryde
@ 2005-06-10 22:41 ` Kevin Ryde
  2005-06-24 21:50   ` Kevin Ryde
  0 siblings, 1 reply; 3+ messages in thread
From: Kevin Ryde @ 2005-06-10 22:41 UTC (permalink / raw)


I made changes to string-filter and string-delete.  At the same time I
made them use substring/shared when nothing removed, since the srfi
allows the result to share with the input, and of course it saves
space to do so.


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: string-delete consing
  2005-06-10 22:41 ` Kevin Ryde
@ 2005-06-24 21:50   ` Kevin Ryde
  0 siblings, 0 replies; 3+ messages in thread
From: Kevin Ryde @ 2005-06-24 21:50 UTC (permalink / raw)


I wrote:
>
> I made changes to string-filter and string-delete.  At the same time I
> made them use substring/shared

I changed my mind about this and made them plain copy-on-write
substrings.  The srfi introduction talks about them being "sharing
allowed" but the individual descriptions only say it might be the
input string returned when there's nothing deleted.


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-06-24 21:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-06-05  1:37 string-delete consing Kevin Ryde
2005-06-10 22:41 ` Kevin Ryde
2005-06-24 21:50   ` Kevin Ryde

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).