winedbg: ResortSymbols optimization

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



ChangeLog:
  - DEBUG_ResortSymbols optimization: avoid one counting loop

Index: programs/winedbg/debugger.h
===================================================================
RCS file: /home/wine/wine/programs/winedbg/debugger.h,v
retrieving revision 1.9
diff -u -r1.9 debugger.h
--- programs/winedbg/debugger.h	1 Apr 2003 00:02:36 -0000	1.9
+++ programs/winedbg/debugger.h	18 Apr 2003 01:17:59 -0000
@@ -570,6 +576,8 @@
     return p;
 }
 #endif
+
+#define DBG_realloc_tab(t,n)	(void *)(t) = DBG_realloc(t, (n) * sizeof(*t))
 
 #define	DEBUG_STATUS_OFFSET		0x80003000
 #define	DEBUG_STATUS_INTERNAL_ERROR	(DEBUG_STATUS_OFFSET+0)
Index: programs/winedbg/hash.c
===================================================================
RCS file: /home/wine/wine/programs/winedbg/hash.c,v
retrieving revision 1.7
diff -u -r1.7 hash.c
--- programs/winedbg/hash.c	19 Feb 2003 03:41:48 -0000	1.7
+++ programs/winedbg/hash.c	18 Apr 2003 01:18:03 -0000
@@ -73,9 +73,9 @@
 
 
 static BOOL DEBUG_GetStackSymbolValue( const char * name, DBG_VALUE *value );
-static int sortlist_valid = FALSE;
 
-static int sorttab_nsym;
+static int sorttab_missing = 0;
+static int sorttab_nsym = 0;
 static struct name_hash ** addr_sorttab = NULL;
 
 static struct name_hash * name_hash_table[NR_NAME_HASH];
@@ -149,30 +137,14 @@
 void
 DEBUG_ResortSymbols(void)
 {
-    struct name_hash *nh;
-    int		nsym = 0;
-    int		i;
-
-    for(i=0; i<NR_NAME_HASH; i++)
-    {
-        for (nh = name_hash_table[i]; nh; nh = nh->next)
-	  {
-	    if( (nh->flags & SYM_INVALID) == 0 )
-	       nsym++;
-	    else
-	       DEBUG_Printf( DBG_CHN_MESG, "Symbol %s (%04lx:%08lx) is invalid\n", 
-                             nh->name, nh->value.addr.seg, nh->value.addr.off );
-          }
-    }
+    const struct name_hash *nh;
+    int		nsym, i;
 
-    sorttab_nsym = nsym;
-    if( nsym == 0 )
-      {
+    if (sorttab_missing == 0)
 	return;
-      }
 
-    addr_sorttab = (struct name_hash **) DBG_realloc(addr_sorttab,
-					 nsym * sizeof(struct name_hash *));
+    sorttab_nsym += sorttab_missing;
+    DBG_realloc_tab(addr_sorttab, sorttab_nsym);
 
     nsym = 0;
     for(i=0; i<NR_NAME_HASH; i++)
@@ -184,10 +156,12 @@
 	  }
     }
 
+    DEBUG_Printf(DBG_CHN_ERR, "Internal error in %s: sorttab: %d/%d, counted: %d\n",
+		    __FUNCTION__, sorttab_missing, sorttab_nsym, nsym);
+
     qsort(addr_sorttab, nsym,
 	  sizeof(struct name_hash *), DEBUG_cmp_sym);
-    sortlist_valid = TRUE;
-
+    sorttab_missing = 0;
 }
 
 /***********************************************************************
@@ -201,6 +175,11 @@
 
     assert(value->cookie == DV_TARGET || value->cookie == DV_HOST);
 
+    /*
+     * First see if we already have an entry for this symbol.  If so
+     * return it, so we don't end up with duplicates.
+     */
+
     hash = name_hash(name);
     for (nh = name_hash_table[hash]; nh; nh = nh->next)
     {
@@ -245,12 +222,14 @@
                  * in that case, we don't clear the invalid flag for all the compilation
                  * units (N_GSYM), and wait to get the symbol from the symtab
                  */
-                if ((flags & SYM_INVALID) == 0)
+                if ((flags & SYM_INVALID) == 0) {
                     nh->flags &= ~SYM_INVALID;
+		    ++sorttab_missing;
+		}
                 return nh;
             }
             /* don't define a symbol twice */
-            if (c == 0 && (flags & SYM_INVALID) == 0) return nh;
+            if (c == 0) return nh;
         }
     }
 
@@ -259,11 +238,6 @@
 		 (flags & SYM_INVALID) ? "invalid" : "  valid", name, source, value->addr.seg, value->addr.off);
 #endif
 
-    /*
-     * First see if we already have an entry for this symbol.  If so
-     * return it, so we don't end up with duplicates.
-     */
-
     new = (struct name_hash *) DBG_alloc(sizeof(struct name_hash));
     new->value = *value;
     new->name = DBG_strdup(name);
@@ -324,7 +277,8 @@
 	}
     }
 
-    sortlist_valid = FALSE;
+    if ( (flags & SYM_INVALID) == 0)
+	++sorttab_missing;
     return new;
 }
 
@@ -336,9 +290,7 @@
    * Free any spare memory that we might have allocated.
    */
   if( nh == NULL )
-    {
       return TRUE;
-    }
 
   if( nh->n_locals != nh->locals_alloc )
     {
@@ -541,9 +540,7 @@
     char modbuf[256];
 
     if( rtn != NULL )
-      {
 	*rtn = NULL;
-      }
 
     if( source != NULL )
       {
@@ -551,15 +548,11 @@
 	source->line = -1;
       }
 
-    if( sortlist_valid == FALSE )
-      {
+    if( sorttab_missing > 0 )
 	DEBUG_ResortSymbols();
-      }
 
-    if( sortlist_valid == FALSE )
-      {
+    if( sorttab_nsym == 0 )
 	return NULL;
-      }
 
     /*
      * FIXME  - use the binary search that we added to
@@ -897,7 +890,7 @@
 {
   int i;
   int depth;
-  struct name_hash *nh;
+  const struct name_hash *nh;
 
   /*
    * Utility function to dump stats about the hash table.
@@ -925,10 +918,8 @@
     struct name_hash * nearest = NULL;
     int mid, high, low;
 
-    if( sortlist_valid == FALSE )
-      {
+    if( sorttab_missing > 0 )
 	DEBUG_ResortSymbols();
-      }
 
     /*
      * Binary search to find closest symbol.
@@ -1077,7 +1068,7 @@
 {
     char buffer[256];
     char * pnt;
-    struct name_hash *nh;
+    const struct name_hash *nh;
 
     for(nh = name_hash_table[name_hash(name)]; nh; nh = nh->next)
       {


[Index of Archives]     [Gimp for Windows]     [Red Hat]     [Samba]     [Yosemite Camping]     [Graphics Cards]     [Wine Home]

  Powered by Linux