This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]