[Patch/RFA] Further speedup locale::operator==

Paolo Carlini pcarlini@suse.de
Wed Apr 28 23:09:00 GMT 2004


Hi,

if I understand well the standard (i.e, 22.1.1.2) it is impossible for
a locale which has no name to acquire one. Indeed, our locale::_Impl::
_M_replace_categories is particularly enlightening about that.

Therefore _M_names[0] == "*" => for every i, _M_names[i] == "*".

This opens up the possibility to further speedup operator==, in
particular when the two locales are different:
 - First, we avoid constructing __name only for testing __name != "*"
 - Then, we compare directly pairs of corresponding _M_names (just
   /one/ comparison suffices for common "simple" (i.e., all the
   _M_names[i] equal) locales.

Indeed, for this:

  std::locale loc1("fr_FR");
  std::locale loc2("de_DE");
  for (int i = 0; i < 10000000; ++i)
    if (loc1 == loc2)
      abort();

current mainline
----------------
11.070u 0.000s 0:11.14 99.3%    0+0k 0+0io 252pf+0w

patched
-------
0.710u 0.000s 0:00.73 97.2%     0+0k 0+0io 250pf+0w

Regtested x86-linux (*)

If nobody finds a flaw in my reasoning I will commit this soon.

Paolo.

(*) The testsuite includes quite a few checks of the assumptions
above: see, f.i., 22_locale/locale/cons/2.cc.

////////////
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: CL_locale_comparison_2
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20040428/acc6f6ca/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: patch_locale_comparison_2
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20040428/acc6f6ca/attachment-0001.ksh>


More information about the Libstdc++ mailing list