9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: "Bruce Ellis" <bruce.ellis@gmail.com>
To: "Fans of the OS Plan 9 from Bell Labs" <9fans@cse.psu.edu>
Subject: Re: [9fans] s_putc and Runes
Date: Mon,  5 Feb 2007 20:41:27 +1100	[thread overview]
Message-ID: <775b8d190702050141k7d64eb82vc5f921e358903a53@mail.gmail.com> (raw)
In-Reply-To: <ee9e417a0702041925l48432744kf91c8813a86c8bf5@mail.gmail.com>

exactly.  time spent optimizing something that uses 3% of the CPU
by 10% is better spent going to the beach, or almost anything.

On 2/5/07, Russ Cox <rsc@swtch.com> wrote:
> > void
> > s_putrune(String *s, Rune r)
> > {
> >         char rbuf[UTFmax];
> >         s_nappend(s, rbuf, runetochar(rbuf, &r));
> > }
>
> This is fine.
>
> > or as part of the library (where I'm a bit shakier on the semantics):
> >
> > void
> > s_putrune(String *s, Rune r)
> > {
> >         char rbuf[UTFmax];
> >         int n;
> >         if(s->ref > 1)
> >                 sysfatal("can't s_putc a shared string");
> >         if (s->ptr >= s->end - n=runelen(r))
> >                 s_grow(s, n+1);
> >         (s->ptr) += runetochar(s->ptr, &r);
> > }
>
> Why bother with these details?  The above is fine.  If it ever
> became too slow, the right thing to do would be to fix s_nappend,
> not code around everything here.  Further, this code is *very*
> unlikely to be the bottleneck -- you're calling it once per at most
> 3 bytes, so the extra little bit you might or might not be saving
> this way pales in comparison to the added complexity.
>
> The main reason there is no Rune support in the String
> library is that it is not widely used.  It was written for upas
> and later extracted, but the interface is a bit clunky.
>
> I confess that most of the time, when I need to write to a
> growable string buffer, I just use fmtstrinit, fmtprint, and fmtstrflush.
> It's just easier, and you get all the print verbs!
>
> Russ
>


  reply	other threads:[~2007-02-05  9:41 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-05  2:41 Joel Salomon
2007-02-05  3:25 ` Russ Cox
2007-02-05  9:41   ` Bruce Ellis [this message]
2007-02-05 12:25   ` erik quanstrom
2007-02-05 19:52   ` Joel Salomon
2007-02-05 21:42     ` Paul Lalonde
2007-02-05 23:57       ` Joel Salomon
2007-02-06  6:23         ` Bruce Ellis

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

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

  git send-email \
    --in-reply-to=775b8d190702050141k7d64eb82vc5f921e358903a53@mail.gmail.com \
    --to=bruce.ellis@gmail.com \
    --cc=9fans@cse.psu.edu \
    /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 NNTP newsgroup(s).