This is the mail archive of the
mailing list for the GDB project.
Re: [RFC] Notes on QUIT and STREQ et.al.
- To: Andrew Cagney <ac131313 at cygnus dot com>, GDB Patches <gdb-patches at sourceware dot cygnus dot com>
- Subject: Re: [RFC] Notes on QUIT and STREQ et.al.
- From: Kevin Buettner <kevinb at cygnus dot com>
- Date: Mon, 13 Mar 2000 09:27:54 -0700
- References: <38CCC819.1071F28E@cygnus.com>
On Mar 13, 9:51pm, Andrew Cagney wrote:
> The attatched spells out the long term prospects of both STREQ et.al.
> and QUIT.
> Look OK to everyone?
> /* Gdb does *lots* of string compares. Use macros to speed them up by
> avoiding function calls if the first characters are not the same. */
> + /* NOTE: cagney/2000-03-13: There is no reason for using these macros
> + in new code (which is just short of marking them as deprecated).
> + While old code can continue to refer to them, new code is better
> + off using the more familar strcmp(). */
> #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)
I haven't looked to see how often (or where) STREQ and STRCMP are
used, but these macros compare the first characters inline in an
attempt to improve performance. Have you assessed the benefits of
doing this? (If these optimizations significantly improve
performance, I think they should stay.)
It seems to me that a decent STREQ macro should also test to see
if the pointers are equal. I.e,
#define STREQ(a,b) ((a == b) || (*(a) == *(b) ? !strcmp ((a), (b)) : 0))