Efficient STRing CoMPares?

Rich Salz rsalz at bbn.com
Tue Mar 19 16:24:43 AEST 1991


In <1991Mar18.174207.7377 at bingvaxu.cc.binghamton.edu> consp06 at bingsuns.cc.binghamton.edu (Robert Konigsberg) writes:
|  Wouldn't it be good then, to include in the macro,
|something to compare the actual POINTERS?  If the pointers are the
|same then the two strings have no CHOICE but to be equivelant.  This
|would really cut down the time under certain situations.
If you're careful about the circumstances under which you use it, you might
want to do something like this:
    #define EQ(p, q)                \
	    ((p) == (q) || ((p)[0] == (q)[0] && strcmp((p), (q)) == 0))
I did this in Coda ("File distribution alternative to rdist", comp.sources.unix
Volume 21) which builds lots of structures with shared strings.  I got a slight
performance gain (1 or 2%, I think).

It's the difference between (eq ... ) and (equal ...), right-p?
	/r$
-- 
Please send comp.sources.unix-related mail to rsalz at uunet.uu.net.
Use a domain-based address or give alternate paths, or you may lose out.



More information about the Comp.lang.c mailing list