Matthew Dillon wrote: > :Roland Mainz wrote: > :> [The following falls under the category "micro-optimisation" but may IMO > :> still be worth an investigation] > :> After working on various parts of OpenSolaris I found that is common to > :> use the following sequence to concatenate strings: > :> -- snip -- > :> ... > :> char *s; > :> ... > :> strcat(s, "foo"); > :> strcat(s, "/"); > :> strcat(s, "bar"); > :> -- snip -- > :> (note: The example is simplified, normally { "foo", ",", "bar" } are > :> normal strings and no static string literals) > :> while this code is simple and easy to understand it is quite inefficient > :> - |strcat()| will always walk |s| each time. If |s| already contains a > :> large path this will be horrible time-consuming. > :> > :> Back in the 1990 timeframe there was the "DICE C" compiler for AmigaOS > :> (AFAIK SAS C/C++ had something similar - but I am not sure) which solved > :> this issue quite cleanly via having a special version of |strcat()| > :> which returned the end of the string instead of the beginning (like > :> ANSI-C |strcat()| does) ... I don't remember the functions's name in > :> "DICE C" anymore - lets call it |strFOOcat()| for now... > : > :[Seems I finally found Matthew Dillons email address...] > :Matthew: Do you remeber how your Amiga DICE-C compiler called the > :function described above ?
> > I don't recall writing a function to do that, but I wrote DICE a long > long time ago. The DICE code is open source now, you can get it from > my web site: http://apollo.backplane.com/ and try to find it :-) I just found it - the function is called |strpcpy()|: -- snip -- NAME stpcpy - copy a string returning a pointer to the end of the destination SYNOPSIS char *ptr = stpcpy(d, s); char *d; char *s; FUNCTION Copy the nul terminated string pointed to by s to the buffer d. The nul is copied. A pointer to the nul character at the end of the copied string in d is returned. NOTE stpcpy() is a non-standard function. While a stpcpy()/stpcpy() combination is more efficient than a strcpy()/strcat() combination, strcpy() and strcat() are standard functions and thus guarenteed to exist in all enviroments. EXAMPLE #include <stdio.h> #include <string.h> #include <assert.h> main() { char *buf1 = "hello"; char *buf2 = "123"; char dest[32]; char *ptr; ptr = stpcpy(dest, buf1); stpcpy(ptr, buf2); puts(dest); /* hello123 */ return(0); } INPUTS char *d; pointer to beginning of destination buffer char *s; pointer to beginning of source string RESULTS char *ptr; pointer to end of data copied to destination buffer SEE ALSO strcpy -- snip -- Note: This extension is already available in Linux - the only thing ToDo would it to port it to Solaris, write a WideChar version of it and then propose it to the standard bodies (which ones ?) ... ---- Bye, Roland -- __ . . __ (o.\ \/ /.o) [EMAIL PROTECTED] \__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer /O /==\ O\ TEL +49 641 7950090 (;O/ \/ \O;) _______________________________________________ opensolaris-discuss mailing list opensolaris-discuss@opensolaris.org