[patch] Code cleanup: Remove search_len parameter

Jan Kratochvil jan.kratochvil@redhat.com
Mon Dec 10 17:51:00 GMT 2012


Hi,

I understand it is very minor update but in some further patches I used
compare_filenames_for_search a lot and it seems awkward to me to always call
func (x, y, strlen (y)).

While one can imagine a use of such length limiting parameter it has no single
utilization in GDB (I did not verify if it had during a check-in).

It may also have been a performance micro-optimization, not sure.

No regressions on {x86_64,x86_64-m32,i686}-fedora18-linux-gnu.

I will check it in.


Thanks,
Jan


gdb/
2012-12-10  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Code cleanup.
	* breakpoint.c (clear_command): Remove variable sal_name_len and its
	initialization, remove it from the compare_filenames_for_search call.
	* dwarf2read.c (dw2_map_symtabs_matching_filename): Remove variable
	name_len and its initialization, remove it from the
	compare_filenames_for_search calls.
	* psymtab.c (partial_map_symtabs_matching_filename): Likewise.
	* symtab.c (compare_filenames_for_search): Remove the search_len
	parameter, update the function comment, new variable search_len
	initialized from SEARCH_NAME.
	(iterate_over_some_symtabs): Remove variable name_len and its
	initialization, remove it from the compare_filenames_for_search calls.
	* symtab.h (compare_filenames_for_search): Remove the search_len
	parameter, 

Diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 01a472c..f55a32b 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -11845,7 +11845,7 @@ clear_command (char *arg, int from_tty)
   make_cleanup (VEC_cleanup (breakpoint_p), &found);
   for (i = 0; i < sals.nelts; i++)
     {
-      int is_abs, sal_name_len;
+      int is_abs;
 
       /* If exact pc given, clear bpts at that pc.
          If line given (pc == 0), clear all bpts on specified line.
@@ -11861,7 +11861,6 @@ clear_command (char *arg, int from_tty)
 
       sal = sals.sals[i];
       is_abs = sal.symtab == NULL ? 1 : IS_ABSOLUTE_PATH (sal.symtab->filename);
-      sal_name_len = is_abs ? 0 : strlen (sal.symtab->filename);
 
       /* Find all matching breakpoints and add them to 'found'.  */
       ALL_BREAKPOINTS (b)
@@ -11894,8 +11893,7 @@ clear_command (char *arg, int from_tty)
 			line_match = 1;
 		      else if (!IS_ABSOLUTE_PATH (sal.symtab->filename)
 			       && compare_filenames_for_search (loc->source_file,
-								sal.symtab->filename,
-								sal_name_len))
+								sal.symtab->filename))
 			line_match = 1;
 		    }
 
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 6eea17e..61093e9 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -3061,7 +3061,6 @@ dw2_map_symtabs_matching_filename (struct objfile *objfile, const char *name,
 {
   int i;
   const char *name_basename = lbasename (name);
-  int name_len = strlen (name);
   int is_abs = IS_ABSOLUTE_PATH (name);
 
   dw2_setup (objfile);
@@ -3088,8 +3087,7 @@ dw2_map_symtabs_matching_filename (struct objfile *objfile, const char *name,
 	  const char *this_name = file_data->file_names[j];
 
 	  if (FILENAME_CMP (name, this_name) == 0
-	      || (!is_abs && compare_filenames_for_search (this_name,
-							   name, name_len)))
+	      || (!is_abs && compare_filenames_for_search (this_name, name)))
 	    {
 	      if (dw2_map_expand_apply (objfile, per_cu,
 					name, full_path, real_path,
@@ -3112,7 +3110,7 @@ dw2_map_symtabs_matching_filename (struct objfile *objfile, const char *name,
 		  && (FILENAME_CMP (full_path, this_real_name) == 0
 		      || (!is_abs
 			  && compare_filenames_for_search (this_real_name,
-							   name, name_len))))
+							   name))))
 		{
 		  if (dw2_map_expand_apply (objfile, per_cu,
 					    name, full_path, real_path,
@@ -3130,7 +3128,7 @@ dw2_map_symtabs_matching_filename (struct objfile *objfile, const char *name,
 		  && (FILENAME_CMP (real_path, this_real_name) == 0
 		      || (!is_abs
 			  && compare_filenames_for_search (this_real_name,
-							   name, name_len))))
+							   name))))
 		{
 		  if (dw2_map_expand_apply (objfile, per_cu,
 					    name, full_path, real_path,
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index 93be085..8eb4954 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -164,7 +164,6 @@ partial_map_symtabs_matching_filename (struct objfile *objfile,
 {
   struct partial_symtab *pst;
   const char *name_basename = lbasename (name);
-  int name_len = strlen (name);
   int is_abs = IS_ABSOLUTE_PATH (name);
 
   ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
@@ -179,8 +178,7 @@ partial_map_symtabs_matching_filename (struct objfile *objfile,
       continue;
 
     if (FILENAME_CMP (name, pst->filename) == 0
-	|| (!is_abs && compare_filenames_for_search (pst->filename,
-						     name, name_len)))
+	|| (!is_abs && compare_filenames_for_search (pst->filename, name)))
       {
 	if (partial_map_expand_apply (objfile, name, full_path, real_path,
 				      pst, callback, data))
@@ -201,7 +199,7 @@ partial_map_symtabs_matching_filename (struct objfile *objfile,
 	if (pst->fullname != NULL
 	    && (FILENAME_CMP (full_path, pst->fullname) == 0
 		|| (!is_abs && compare_filenames_for_search (pst->fullname,
-							     name, name_len))))
+							     name))))
 	  {
 	    if (partial_map_expand_apply (objfile, name, full_path, real_path,
 					  pst, callback, data))
@@ -220,8 +218,7 @@ partial_map_symtabs_matching_filename (struct objfile *objfile,
           }
 	if (rp != NULL
 	    && (FILENAME_CMP (real_path, rp) == 0
-		|| (!is_abs && compare_filenames_for_search (real_path,
-							     name, name_len))))
+		|| (!is_abs && compare_filenames_for_search (real_path, name))))
 	  {
 	    if (partial_map_expand_apply (objfile, name, full_path, real_path,
 					  pst, callback, data))
diff --git a/gdb/symtab.c b/gdb/symtab.c
index cf32a8c..f5276e2 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -147,15 +147,14 @@ const struct block *block_found;
 
 /* See whether FILENAME matches SEARCH_NAME using the rule that we
    advertise to the user.  (The manual's description of linespecs
-   describes what we advertise).  SEARCH_LEN is the length of
-   SEARCH_NAME.  We assume that SEARCH_NAME is a relative path.
-   Returns true if they match, false otherwise.  */
+   describes what we advertise).  We assume that SEARCH_NAME is
+   a relative path.  Returns true if they match, false otherwise.  */
 
 int
-compare_filenames_for_search (const char *filename, const char *search_name,
-			      int search_len)
+compare_filenames_for_search (const char *filename, const char *search_name)
 {
   int len = strlen (filename);
+  size_t search_len = strlen (search_name);
 
   if (len < search_len)
     return 0;
@@ -196,7 +195,6 @@ iterate_over_some_symtabs (const char *name,
 {
   struct symtab *s = NULL;
   const char* base_name = lbasename (name);
-  int name_len = strlen (name);
   int is_abs = IS_ABSOLUTE_PATH (name);
 
   for (s = first; s != NULL && s != after_last; s = s->next)
@@ -208,7 +206,7 @@ iterate_over_some_symtabs (const char *name,
 	    return 1;
 	}
 
-      if (!is_abs && compare_filenames_for_search (s->filename, name, name_len))
+      if (!is_abs && compare_filenames_for_search (s->filename, name))
 	{
 	  if (callback (s, data))
 	    return 1;
@@ -233,8 +231,7 @@ iterate_over_some_symtabs (const char *name,
 	      return 1;
           }
 
-	if (fp != NULL && !is_abs && compare_filenames_for_search (fp, name,
-								   name_len))
+	if (fp != NULL && !is_abs && compare_filenames_for_search (fp, name))
 	  {
 	    if (callback (s, data))
 	      return 1;
@@ -256,7 +253,7 @@ iterate_over_some_symtabs (const char *name,
 		  return 1;
 	      }
 
-	    if (!is_abs && compare_filenames_for_search (rp, name, name_len))
+	    if (!is_abs && compare_filenames_for_search (rp, name))
 	      {
 		if (callback (s, data))
 		  return 1;
diff --git a/gdb/symtab.h b/gdb/symtab.h
index a933132..0279457 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -1286,8 +1286,7 @@ extern int symtab_create_debug;
 extern int basenames_may_differ;
 
 int compare_filenames_for_search (const char *filename,
-				  const char *search_name,
-				  int search_len);
+				  const char *search_name);
 
 int iterate_over_some_symtabs (const char *name,
 			       const char *full_path,



More information about the Gdb-patches mailing list