This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
RE: Q about ctype.narrow
- From: Pétur Runólfsson <peturr02 at ru dot is>
- To: "Paolo Carlini" <pcarlini at unitus dot it>,"Jerry Quinn" <jlquinn at optonline dot net>
- Cc: "libstdc++" <libstdc++ at gcc dot gnu dot org>
- Date: Wed, 26 Nov 2003 15:55:08 -0000
- Subject: RE: Q about ctype.narrow
Paolo Carlini wrote:
> Jerry Quinn wrote:
> >What is the benefit in this case of keeping the cache table elsewhere?
> >
> Yes, I'm with Jerry in not seeing clearly the benefit.
if (table[c]) return table[c];
return table[c] = do_narrow(c, default);
vs.
char narrow(char c) const { return narrow_table[(unsigned char)c]; }
The second version avoids a branch, and avoids a virtual call for
characters that are not mapped. (I have no idea if it makes any
measurable difference.)
> I was hoping that something similar could be done as part of the ctype
> constructor, basically filling a couple of tables with btowc/wctob.
>
> I hasten to point out that my scope was therefore *limited*: the /default/
> do_widen and do_narrow, not a general caching mechanism to be put inside
> widen
> and narrow! Again, the current moneypunct virtuals were my example.
>
> Wouldn't that be also quite useful in order to speed up many applications
> of
> widen and narrow?
Yes, this should help. (I tried something like this once, and found that
it was actually faster than the glibc equivalent, even though the
virtual function call was not eliminated.)
Pétur