focused code review

Bill Medland billmedland at mercuryspeed.com
Fri May 28 10:26:26 CDT 2004


On May 27, 2004 10:25 pm, Glen Kaukola wrote:
> Hi,
>
> So one project suggested on the website is to do a focused code review.
>   In particular it talks about getting rid of inefficient uses of
> strcat.  But that leaves me wondering what exactly constitutes an
> inefficient use of strcat?  If anyone could provide an example I'd
> appreciate it.  Thanks.
>
> Glen
(Not that I get particularly worked up about it; I find using strcat to be 
more readable)

If you know the length of the string onto which you are adding the second 
string then you can simply strcpy; it saves the code remeasuring the string.

e.g. (really lame example)

void foo (const char *s1, const char *s2, char *buf, size_t len_buf)
{
    int len_s1 = strlen(s1);
    int len_s2 = strlen(s2);
    if (len_s1 + len_s2 < len_buf && buf)
    {
        strcpy (buf, s1);
        strcpy (buf+len_s1, s2);
    }
}

-- 
Bill Medland
mailto:billmedland at mercuryspeed.com
http://webhome.idirect.com/~kbmed




More information about the wine-devel mailing list