[Lldb-commits] [lldb] r105835 - in /lldb/trunk: include/lldb/Symbol/Symtab.h source/Symbol/Symtab.cpp

Owen Anderson resistor at mac.com
Fri Jun 11 14:07:26 PDT 2010


Author: resistor
Date: Fri Jun 11 16:07:26 2010
New Revision: 105835

URL: http://llvm.org/viewvc/llvm-project?rev=105835&view=rev
Log:
Revert my previous patch.  Apparently the code-size impact of std::sort isn't acceptable.

Modified:
    lldb/trunk/include/lldb/Symbol/Symtab.h
    lldb/trunk/source/Symbol/Symtab.cpp

Modified: lldb/trunk/include/lldb/Symbol/Symtab.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/Symtab.h?rev=105835&r1=105834&r2=105835&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/Symtab.h (original)
+++ lldb/trunk/include/lldb/Symbol/Symtab.h Fri Jun 11 16:07:26 2010
@@ -59,6 +59,8 @@
     typedef collection::iterator        iterator;
     typedef collection::const_iterator  const_iterator;
 
+    static  int         CompareSymbolValueByIndex (void *thunk, const void *a, const void *b);
+    static  int         CompareSymbolValueByIndexLinux (const void *a, const void *b, void *thunk);
             void        InitNameIndexes ();
             void        InitAddressIndexes ();
 

Modified: lldb/trunk/source/Symbol/Symtab.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/Symtab.cpp?rev=105835&r1=105834&r2=105835&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/Symtab.cpp (original)
+++ lldb/trunk/source/Symbol/Symtab.cpp Fri Jun 11 16:07:26 2010
@@ -214,36 +214,46 @@
     const Symbol *symbols;
 };
 
-namespace {
-    struct SymbolIndexComparator {
-        const std::vector<Symbol>& symbols;
-        SymbolIndexComparator(const std::vector<Symbol>& s) : symbols(s) { }
-        bool operator()(uint32_t index_a, uint32_t index_b) {
-            addr_t value_a;
-            addr_t value_b;
-            if (symbols[index_a].GetValue().GetSection() == symbols[index_b].GetValue().GetSection()) {
-                value_a = symbols[index_a].GetValue ().GetOffset();
-                value_b = symbols[index_b].GetValue ().GetOffset();
-            } else {
-                value_a = symbols[index_a].GetValue ().GetFileAddress();
-                value_b = symbols[index_b].GetValue ().GetFileAddress();
-            }
+int
+Symtab::CompareSymbolValueByIndex (void *thunk, const void *a, const void *b)
+{
+    const Symbol *symbols = (const Symbol *)thunk;
+    uint32_t index_a = *((uint32_t *) a);
+    uint32_t index_b = *((uint32_t *) b);
 
-            if (value_a == value_b) {
-                // The if the values are equal, use the original symbol user ID
-                lldb::user_id_t uid_a = symbols[index_a].GetID();
-                lldb::user_id_t uid_b = symbols[index_b].GetID();
-                if (uid_a < uid_b)
-                    return true;
-                if (uid_a > uid_b)
-                    return false;
-                return false;
-            } else if (value_a < value_b)
-                return true;
-        
-            return false;
-        }
-    };
+    addr_t value_a;
+    addr_t value_b;
+    if (symbols[index_a].GetValue().GetSection() == symbols[index_b].GetValue().GetSection())
+    {
+        value_a = symbols[index_a].GetValue ().GetOffset();
+        value_b = symbols[index_b].GetValue ().GetOffset();
+    }
+    else
+    {
+        value_a = symbols[index_a].GetValue ().GetFileAddress();
+        value_b = symbols[index_b].GetValue ().GetFileAddress();
+    }
+
+    if (value_a == value_b)
+    {
+        // The if the values are equal, use the original symbol user ID
+        lldb::user_id_t uid_a = symbols[index_a].GetID();
+        lldb::user_id_t uid_b = symbols[index_b].GetID();
+        if (uid_a < uid_b)
+            return -1;
+        if (uid_a > uid_b)
+            return 1;
+        return 0;
+    }
+    else if (value_a < value_b)
+        return -1;
+
+    return 1;
+}
+
+int Symtab::CompareSymbolValueByIndexLinux(const void* a, const void* b, void* thunk) 
+{
+    return CompareSymbolValueByIndex(thunk, a, b);
 }
 
 void
@@ -253,8 +263,13 @@
     if (indexes.size() <= 1)
         return;
 
-    // Sort the indexes in place using std::sort
-    std::sort(indexes.begin(), indexes.end(), SymbolIndexComparator(m_symbols));
+    // Sort the indexes in place using qsort
+    // FIXME: (WRONGDEFINE) Need a better define for this! 
+#ifdef __APPLE__
+    ::qsort_r (&indexes[0], indexes.size(), sizeof(uint32_t), (void *)&m_symbols[0], Symtab::CompareSymbolValueByIndex);
+#else
+    ::qsort_r (&indexes[0], indexes.size(), sizeof(uint32_t), CompareSymbolValueByIndexLinux, (void *)&m_symbols[0]);
+#endif
 
     // Remove any duplicates if requested
     if (remove_duplicates)





More information about the lldb-commits mailing list