[RFC] Notes on QUIT and STREQ et.al.

Andrew Cagney ac131313@cygnus.com
Mon Mar 13 18:36:00 GMT 2000


Andrew Cagney wrote:
> 
> The attatched spells out the long term prospects of both STREQ et.al.
> and QUIT.

FYI, I checked in the attatched.

I resisted the temptation to rewrite the macros eliminating ``?:'' :-)
Knowing my luck, I'd firstly get it wrong and  secondly it would turn
out that some code somewhere relied on the existing behavour.

	enjoy,
		Andrew
Mon Mar 13 21:21:41 2000  Andrew Cagney  <cagney@b1.cygnus.com>

	* defs.h (STREQ, STRCMP, STREQN): Document that these macros are
 	somewhat redundant.
	(QUIT): Note that this can probably be replaced by a function.

Index: defs.h
===================================================================
RCS file: /cvs/src/src/gdb/defs.h,v
retrieving revision 1.11
diff -p -r1.11 defs.h
*** defs.h	2000/03/13 07:30:00	1.11
--- defs.h	2000/03/14 02:27:37
*************** extern int core_addr_greaterthan (CORE_A
*** 117,125 ****
  #define max(a, b) ((a) > (b) ? (a) : (b))
  #endif
  
! /* Gdb does *lots* of string compares.  Use macros to speed them up by
!    avoiding function calls if the first characters are not the same. */
  
  #define STRCMP(a,b) (*(a) == *(b) ? strcmp ((a), (b)) : (int)*(a) - (int)*(b))
  #define STREQ(a,b) (*(a) == *(b) ? !strcmp ((a), (b)) : 0)
  #define STREQN(a,b,c) (*(a) == *(b) ? !strncmp ((a), (b), (c)) : 0)
--- 117,140 ----
  #define max(a, b) ((a) > (b) ? (a) : (b))
  #endif
  
! /* Macros to do string compares.
  
+    NOTE: cagney/2000-03-14:
+ 
+    While old code can continue to refer to these macros, new code is
+    probably better off using strcmp() directly vis: ``strcmp() == 0''
+    and ``strcmp() != 0''.
+ 
+    This is because modern compilers can directly inline strcmp()
+    making the original justification for these macros - avoid function
+    call overhead by pre-testing the first characters
+    (``*X==*Y?...:0'') - redundant.
+ 
+    ``Even if [...] testing the first character does have a modest
+    performance improvement, I'd rather that whenever a performance
+    issue is found that we spend the effort on algorithmic
+    optimizations than micro-optimizing.'' J.T. */
+ 
  #define STRCMP(a,b) (*(a) == *(b) ? strcmp ((a), (b)) : (int)*(a) - (int)*(b))
  #define STREQ(a,b) (*(a) == *(b) ? !strcmp ((a), (b)) : 0)
  #define STREQN(a,b,c) (*(a) == *(b) ? !strncmp ((a), (b), (c)) : 0)
*************** extern int immediate_quit;
*** 152,157 ****
--- 167,179 ----
  extern int sevenbit_strings;
  
  extern void quit (void);
+ 
+ /* FIXME: cagney/2000-03-13: It has been suggested that the peformance
+    benefits of having a ``QUIT'' macro rather than a function are
+    marginal.  If the overhead of a QUIT function call is proving
+    significant then its calling frequency should probably be reduced
+    [kingdon].  A profile analyzing the current situtation is
+    needed. */
  
  #ifdef QUIT
  /* do twice to force compiler warning */


More information about the Gdb-patches mailing list