Q about ctype.narrow
Pétur Runólfsson
peturr02@ru.is
Wed Nov 26 15:55:00 GMT 2003
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
More information about the Libstdc++
mailing list