Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!cbosgd!ihnp4!ptsfa!lll-tis!mordor!sri-spam!rutgers!gatech!bloom-beacon!husc6!cmcl2!brl-adm!brl-smoke!gwyn From: gwyn@brl-smoke.UUCP Newsgroups: comp.lang.c Subject: Re: string equality/comparison optimization Message-ID: <6086@brl-smoke.ARPA> Date: Thu, 9-Jul-87 01:09:38 EDT Article-I.D.: brl-smok.6086 Posted: Thu Jul 9 01:09:38 1987 Date-Received: Sat, 11-Jul-87 16:39:36 EDT References: <8011@brl-adm.ARPA> <1711@umn-cs.UUCP> <1500@xanth.UUCP> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB)) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 15 In article <1500@xanth.UUCP> kyle@xanth.UUCP (Kyle Jones) writes: >But then wouldn't the comparison be just as slow using strcmp(), since it too >must compare bytes? Not necessarily. An old trick used in some implementations of memcpy() on systems that don't have special block-move instructions can also be used for strcmp(): Take care of the individual chars until one pointer has been incremented so that it is word-aligned; then, if the second pointer is also word-aligned, enter a special loop that does full-word comparisons, with a bit of extra code to handle the loop termination correctly. I don't recommend this, however, unless you're expecting to handle mostly long strings. Since that's unlikely, the odds are that the extra bookkeeping overhead won't be justified for general adoption.