M
Mark
Netocrat said:As for your implementation, a little messy and contains unnecessary
overhead... [snip code]
Untested (I know it won't work with the driver below for as I've
previously stated, it's flawed) but it should outperform both your and
the
original poster's functions If you do decide to test it, let us know
the results.
Approximately 4 times slower on my machine. Why did you expect better
performance? Even though you are getting back the length and don't have
to do a separate strlen, sprintf is by its nature much more complex than
strcat or strcpy and no doubt these two simple library functions are
much more highly optimised for this task, probably by using processor
instructions that copy many bytes at a time, which I would not expect
sprintf to be optimised to do.
But yes, your implementation is neat and concise.
You're right... I guess I should have tested it first.
I expected sprintf()'s performance to be nearly the same
as strcpy()'s when no conversion specifiers were present
in the format string... and that 1 pass with sprintf()
would outperform the 2 passes needed by strcpy() and strlen().
Guess I was mistaken.
Here's another version... tested this time... and this one should
substantially outperform the other.
char *
vstrcat(char *s, ...)
{
register char *p = &s[strlen(s)];
register char *arg;
va_list ap;
va_start(ap, s);
while((arg = va_arg(ap, char *)) != NULL)
while((*p++ = *arg++) != 0);
va_end(ap);
return s;
}
Mark