From Craig Silverstein: Only sort for suffixes with -O2.
authorIan Lance Taylor <iant@google.com>
Fri, 21 Sep 2007 15:54:07 +0000 (15:54 +0000)
committerIan Lance Taylor <iant@google.com>
Fri, 21 Sep 2007 15:54:07 +0000 (15:54 +0000)
gold/po/gold.pot
gold/stringpool.cc

index 286ba19cab68c996de730cfab24548c1b0516b7e..b4f6bbdb32ac319e5059801f7b7661f1cf160d7c 100644 (file)
@@ -8,7 +8,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2007-09-21 00:18-0700\n"
+"POT-Creation-Date: 2007-09-21 08:52-0700\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
index c0a4ae72c99973006b417394a394a082593fba34..43f63282db299f9d0e4207b1cac689d0d524dcb7 100644 (file)
@@ -7,6 +7,7 @@
 #include <vector>
 
 #include "output.h"
+#include "parameters.h"
 #include "stringpool.h"
 
 namespace gold
@@ -303,42 +304,65 @@ Stringpool_template<Stringpool_char>::set_string_offsets()
       return;
     }
 
-  size_t count = this->string_set_.size();
-
-  std::vector<Stringpool_sort_info> v;
-  v.reserve(count);
-
-  for (typename String_set_type::iterator p = this->string_set_.begin();
-       p != this->string_set_.end();
-       ++p)
-    v.push_back(Stringpool_sort_info(p, string_length(p->first)));
-
-  std::sort(v.begin(), v.end(), Stringpool_sort_comparison());
-
   const size_t charsize = sizeof(Stringpool_char);
 
   // Offset 0 may be reserved for the empty string.
   off_t offset = this->zero_null_ ? charsize : 0;
 
-  for (typename std::vector<Stringpool_sort_info>::iterator last = v.end(),
-         curr = v.begin();
-       curr != v.end();
-       last = curr++)
+  // Sorting to find suffixes can take over 25% of the total CPU time
+  // used by the linker.  Since it's merely an optimization to reduce
+  // the strtab size, and gives a relatively small benefit (it's
+  // typically rare for a symbol to be a suffix of another), we only
+  // take the time to sort when the user asks for heavy optimization.
+  if (parameters->optimization_level() < 2)
     {
-      if (this->zero_null_ && curr->it->first[0] == 0)
-       curr->it->second.second = 0;
-      else if (last != v.end()
-               && is_suffix(curr->it->first, curr->string_length,
-                            last->it->first, last->string_length))
-       curr->it->second.second = (last->it->second.second
-                                   + ((last->string_length
-                                       - curr->string_length)
-                                      * charsize));
-      else
-       {
-         curr->it->second.second = offset;
-         offset += (curr->string_length + 1) * charsize;
-       }
+      for (typename String_set_type::iterator curr = this->string_set_.begin();
+           curr != this->string_set_.end();
+           curr++)
+        {
+          if (this->zero_null_ && curr->first[0] == 0)
+            curr->second.second = 0;
+          else
+            {
+              curr->second.second = offset;
+              offset += (string_length(curr->first) + 1) * charsize;
+            }
+        }
+    }
+  else
+    {
+      size_t count = this->string_set_.size();
+
+      std::vector<Stringpool_sort_info> v;
+      v.reserve(count);
+
+      for (typename String_set_type::iterator p = this->string_set_.begin();
+           p != this->string_set_.end();
+           ++p)
+        v.push_back(Stringpool_sort_info(p, string_length(p->first)));
+
+      std::sort(v.begin(), v.end(), Stringpool_sort_comparison());
+
+      for (typename std::vector<Stringpool_sort_info>::iterator last = v.end(),
+             curr = v.begin();
+           curr != v.end();
+           last = curr++)
+        {
+          if (this->zero_null_ && curr->it->first[0] == 0)
+            curr->it->second.second = 0;
+          else if (last != v.end()
+                   && is_suffix(curr->it->first, curr->string_length,
+                                last->it->first, last->string_length))
+            curr->it->second.second = (last->it->second.second
+                                       + ((last->string_length
+                                           - curr->string_length)
+                                          * charsize));
+          else
+            {
+              curr->it->second.second = offset;
+              offset += (curr->string_length + 1) * charsize;
+            }
+        }
     }
 
   this->strtab_size_ = offset;
This page took 0.034803 seconds and 4 git commands to generate.