winedbg: minor code readability fix

Michal Janusz Miroslaw M.Miroslaw at elka.pw.edu.pl
Fri Sep 19 09:09:25 CDT 2003


ChangeLog:
  - DEBUG_AddSymbol: make it more readable by extracting memory-saving
    optimization as DEBUG_strduponce

index: programs/winedbg/debugger.h
===================================================================
RCS file: /home/wine/wine/programs/winedbg/debugger.h,v
retrieving revision 1.10
diff -u -r1.10 debugger.h
--- programs/winedbg/debugger.h	5 Sep 2003 23:15:41 -0000	1.10
+++ programs/winedbg/debugger.h	19 Sep 2003 03:51:27 -0000
@@ -430,6 +430,10 @@
 extern int  DEBUG_PrintStringA( int chnl, const DBG_ADDR* address, int len );
 extern int  DEBUG_PrintStringW( int chnl, const DBG_ADDR* address, int len );
 
+#define STRONCE_SOURCEFILE	0
+#define STRONCE_LAST		STRONCE_SOURCEFILE
+extern char *DEBUG_strduponce(int stronce_id, const char *str);
+
   /* debugger/module.c */
 extern int  DEBUG_LoadEntryPoints( const char * prefix );
 extern void DEBUG_LoadModule32( const char* name, HANDLE hFile, void *base );
Index: programs/winedbg/hash.c
===================================================================
RCS file: /home/wine/wine/programs/winedbg/hash.c,v
retrieving revision 1.10
diff -u -r1.10 hash.c
--- programs/winedbg/hash.c	7 Aug 2003 02:56:55 -0000	1.10
+++ programs/winedbg/hash.c	19 Sep 2003 03:51:28 -0000
@@ -201,8 +201,6 @@
 {
     struct name_hash  * new;
     struct name_hash *nh;
-    static char  prev_source[PATH_MAX] = {'\0', };
-    static char * prev_duped_source = NULL;
     int hash;
 
     assert(value->cookie == DV_TARGET || value->cookie == DV_HOST);
@@ -269,28 +267,7 @@
     new = (struct name_hash *) DBG_alloc(sizeof(struct name_hash));
     new->value = *value;
     new->name = DBG_strdup(name);
-
-    if( source != NULL )
-      {
-	/*
-	 * This is an enhancement to reduce memory consumption.  The idea
-	 * is that we duplicate a given string only once.  This is a big
-	 * win if there are lots of symbols defined in a given source file.
-	 */
-	if( strcmp(source, prev_source) == 0 )
-	  {
-	    new->sourcefile = prev_duped_source;
-	  }
-	else
-	  {
-	    strcpy(prev_source, source);
-	    prev_duped_source = new->sourcefile = DBG_strdup(source);
-	  }
-      }
-    else
-      {
-	new->sourcefile = NULL;
-      }
+    new->sourcefile = DEBUG_strduponce(STRONCE_SOURCEFILE, source);
 
     new->n_lines	= 0;
     new->lines_alloc	= 0;
Index: programs/winedbg/memory.c
===================================================================
RCS file: /home/wine/wine/programs/winedbg/memory.c,v
retrieving revision 1.4
diff -u -r1.4 memory.c
--- programs/winedbg/memory.c	7 Aug 2003 02:56:35 -0000	1.4
+++ programs/winedbg/memory.c	19 Sep 2003 03:51:28 -0000
@@ -388,3 +388,23 @@
     }
     return written; /* number of actually written chars */
 }
+
+/*
+ * DEBUG_strduponce
+ *
+ * Function used to try to avoid duplicated constant strings such
+ * as source file names.
+ */
+static char *str_lists[STRONCE_LAST+1] = { NULL, };
+
+char *DEBUG_strduponce(int str_list, const char *str)
+{
+	if (!str)
+		return NULL;
+
+	if (str_lists[str_list] && !strcmp(str, str_lists[str_list]))
+		return str_lists[str_list];
+
+	return (str_lists[str_list] = DBG_strdup(str));
+}
+



More information about the wine-patches mailing list