This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Still improving! (Was: Re: [PATCH] Avoid strtok for thread safety)
On Wed, Nov 27, 2002 at 09:41:28AM +0100, Paolo Carlini wrote:
> Nathan Myers wrote:
>
> >Note that the C++ algorithms have much nicer termination semantics than
> >most of the C string functions (strcspn excepted).
> >
> Nice, I didn't consider that... However, in the meanwhile, I tried to post
> (tested x86-linux), which basically avoid half the finds thanks to the a
> priori knowldege of the names of the various categories. Something like
> this:
> __end = strpbrk(__beg, ";");
> ...
> __beg = __end + strlen(_S_categories[__i + 1]) + 2;
(I think you want strchr or find there, not strpbrk.) Anyway, strlen
is not any faster than find. If the category names were stored with
their lengths (e.g. as std::string) then this way could be quicker.
strlen is always slow.
Are we sure that the order of components is always the same?
If so, what a dumb format. If not, the function might need
to search the names as it goes.
> Also, it seems to me that in the existing practice of locale implementation
> in v3 C++ algorithms like std::copy and std::find are not used, dunno
> exactly why, however...
Just old bad habits, mistrust, and superstition. Some people think that
the C functions must be better optimized, despite that the C++ functions
are more readily optimizable. For example, std::copy applied to (e.g.)
pointers always knows the alignment of its arguments, where memcpy has
to check. Mostly, though, it's just bad habit.
Once in a while, of course, the C function is the right thing.
Nathan Myers
ncm-nospam@cantrip.org