[prev in list] [next in list] [prev in thread] [next in thread]
List: wine-devel
Subject: Re: focused code review
From: Bill Medland <billmedland () mercuryspeed ! com>
Date: 2004-05-28 15:26:26
Message-ID: 200405280826.26564.billmedland () mercuryspeed ! com
[Download RAW message or body]
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@mercuryspeed.com
http://webhome.idirect.com/~kbmed
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic