🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.arch
Article #13612

Re: String Handling -- Incompetence of run-time libraries

#13612
From: adam
Date: Fri, 10 Apr 1987 09:43
35 lines
1784 bytes
In article <9996@sri-spam.istc.sri.com> robert@sri-spam.UUCP (Robert Allen) writes:
>
>To further speed this up you could write it as:
>
>	strcpy2(ss1,ss2)
>	register char *ss1, *ss2;
>	{
>	    while (*s1++ = *s2++)
>	    ;
>	}
>
>thus eliminating two assignments and two local variables.
>
If your machine doesn't complain at char-int alignment, try

strcmp2(s1, s2)
register short int *s1, *s2;
{
	while (*s1 == *s2++)
		if (!((*s1++ & 255) && (*(char *)s1)))
			return(0);
	return(*s1 - *--s2);
}

This relies on the fact that it doesn't matter if you compare the NULLs at the
end of two equal strings or not. We go along the string twice as fast because
of the 16 bit operations, although there is a slight penalty due to the extra
test. The alignment problem only comes in if either of 
the strings begins on an odd boundary, which is fairly unusual anyway. 
Also watch the last part of the 'if' condition - this won't work on 
some machines, you may have to add 1 to the pointer.
-- 
       -Adam.

/* If at first it don't compile, kludge, kludge again.*/
Technical Details
Message-ID: <531@gec-mi-at.co.uk>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watnot!watmath!clyde!rutgers!seismo!mcvax!ukc!hrc63!miduet!adam
References: <15292@amdcad.UUCP> <978@ames.UUCP> <15694@sun.uucp>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watnot!watmath!clyde!rutgers!seismo!mcvax!ukc!hrc63!miduet!adam
From: adam@miduet.UUCP
Newsgroups: comp.arch,comp.lang.c
Subject: Re: String Handling -- Incompetence of run-time libraries
Message-ID: <531@gec-mi-at.co.uk>
Date: Fri, 10-Apr-87 04:43:48 EST
Article-I.D.: gec-mi-a.531
Posted: Fri Apr 10 04:43:48 1987
Date-Received: Wed, 15-Apr-87 00:48:53 EST
References: <15292@amdcad.UUCP> <978@ames.UUCP> <15694@sun.uucp>
Reply-To: adam@gec-mi-at.co.uk (Adam Quantrill)
Organization: Marconi Instruments Ltd., St. Albans, Herts, UK
Lines: 35
Keywords: instruction set architectures, strcpy