From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kevin Buettner To: Andrew Cagney , GDB Patches Subject: Re: [RFC] Notes on QUIT and STREQ et.al. Date: Mon, 13 Mar 2000 08:28:00 -0000 Message-id: <1000313162754.ZM28984@ocotillo.lan> References: <38CCC819.1071F28E@cygnus.com> X-SW-Source: 2000-03/msg00230.html 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)) Kevin >From dan@cgsoftware.com Mon Mar 13 08:52:00 2000 From: Daniel Berlin To: Kevin Buettner Cc: Andrew Cagney , GDB Patches Subject: Re: [RFC] Notes on QUIT and STREQ et.al. Date: Mon, 13 Mar 2000 08:52:00 -0000 Message-id: References: <1000313162754.ZM28984@ocotillo.lan> X-SW-Source: 2000-03/msg00231.html Content-length: 631 > > 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.) I'll check out the performance. I know GCC has a strlen expander, but no strcmp expander, so it might be a benefit. > > 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)) > > Kevin >