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: [Patch] Speedup locale::operator==


I was going to ask why construct the name string before I went and really read the underlying code.

Upon further reflection, the real question is why the compiler can't hoist the first test above the string constructor.  Are we required to run it by the language, or is it just a limitation in the current optimizer?  And if so, will tree-ssa be able to optimize it?

BTW, nice little improvement :-)

Jerry Quinn

----- Original Message -----
From: Paolo Carlini <pcarlini@suse.de>
Date: Wednesday, April 14, 2004 12:47 pm
Subject: [Patch] Speedup locale::operator==

> Hi,
> 
> I noticed some time ago that we (*) weren't exploting the ref-counted
> nature of locale in operator==.
> 
> For this stupid testcase (P4-2400, -O2):
> 
>  std::locale loc1("fr_FR");
>  std::locale loc2 = loc1;
>  bool test = false;
>  for (int i = 0; i < 10000000; ++i)
>    if (loc2 == loc1)
>      test = true;
> 
> current mainline
> ----------------
> 5.190u 0.000s 0:05.21 99.6%     0+0k 0+0io 245pf+0w
> 
> patched
> -------
> 0.150u 0.000s 0:00.15 100.0%    0+0k 0+0io 242pf+0w
> 
> Regtested x86-linux, will commit later.
> 
> Paolo.
> 
> (*) At variance with our famous competitor ;) ...
> 
> //////////////
> 
diff -urN libstdc++-v3-orig/src/locale.cc libstdc++-v3/src/locale.cc
--- libstdc++-v3-orig/src/locale.cc	2004-02-27 01:49:49.000000000 +0100
+++ libstdc++-v3/src/locale.cc	2004-04-14 18:09:55.000000000 +0200
@@ -70,9 +70,16 @@
   bool
   locale::operator==(const locale& __rhs) const throw()
   {
-    string __name = this->name();
-    return (_M_impl == __rhs._M_impl 
-	    || (__name != "*" && __name == __rhs.name()));
+    bool __ret = false;
+    if (_M_impl == __rhs._M_impl)
+      __ret = true;
+    else
+      {
+	const string __name = this->name();
+	if (__name != "*" && __name == __rhs.name())
+	  __ret = true;
+      }
+    return __ret;
   }
 
   const locale&

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