Unless we're talking an inner and very intensive loop, all this is a bit silly.
However, assuming that it does make sense, sprintf variants are not part of the answer. They're interpreted and var-arg type, both of which are little good for efficiency. More like something along these lines:
char *tmpdst = dst;
strcpy (tmpdst, src1); tmpdst += strlen (src1); strcpy (tmpdst, src2); tmpdst += strlen (src2); strcpy (tmpdst, src3); tmpdst += strlen (src3); ... strcpy (tmpdst, srcN); tmpdst += strlen (srcN); ...
This works even better when the strlen calls have known results.
Of course, nothing keeps the compiler from noticing a certain pattern of sprintf calls can producing an equaivalent of the above, but right now gcc will not do that if I recall correctly.
Morten
On 2 Dec 2002, Morten Welinder wrote: [...]
Unless we're talking an inner and very intensive loop, all this is a bit silly.
However, assuming that it does make sense, sprintf variants are not part of the answer. They're interpreted and var-arg type
Why would vararg be a problem performance-wise?
More like something along these lines:
char *tmpdst = dst;
strcpy (tmpdst, src1); tmpdst += strlen (src1);
[...]
This works even better when the strlen calls have known results.
Except usually src* are constant strings and it's a major pain from a maintainability and readability point of vue to have to duplicate them. And whenever src* is not a constant, the above is twice as slow as cpycat because each string is read twice (once by strcpy and another time by strlen).