Re: pen_strdup (0.17.1) speed up

From: Dominic Son <dominicson_at_gmail.com>
Date: Mon, 27 Aug 2007 01:51:01 -0700

i dont understand why i am receiving many of your emails..

On 8/27/07, Nigel Horne <njh_at_bandsman.co.uk> wrote:
> The length of the string is calculated twice, once by strlen and once (by implication of
> looking for the NUL terminator) by strcpy.
>
> Better to calculated it once and remember:
>
>
> *** Open.c 2007-08-27 08:53:40.000000000 +0100
> --- pen.c 2007-08-27 08:55:50.000000000 +0100
> ***************
> *** 241,248 ****
>
> static char *pen_strdup(char *p)
> {
> ! char *b = pen_malloc(strlen(p)+1);
> ! return strcpy(b, p);
> }
>
> static int pen_strncasecmp(const char *p, const char *q, size_t n)
> --- 241,254 ----
>
> static char *pen_strdup(char *p)
> {
> ! size_t len = strlen(p);
> ! char *b = pen_malloc(len + 1);
> !
> ! if(b) {
> ! memcpy(b, p, len);
> ! b[len] = '\0';
> ! }
> ! return b;
> }
>
> static int pen_strncasecmp(const char *p, const char *q, size_t n)
>
> --
> Nigel Horne. Adjudicator, Arranger, Band Trainer, Composer, Tutor, Typesetter.
> NJH Music, Barnsley, UK. ICQ#20252325
> njh@bandsman.co.uk http://www.bandsman.co.uk
>
>

-- 
Anything else, let me know.
- Dominic Son
The ability to simplify means to eliminate the unnecessary so that the
necessary may speak.
-Hofstadter's Law
Received on Mon Aug 27 2007 - 11:18:33 CEST

This archive was generated by hypermail 2.2.0 : Mon Aug 27 2007 - 11:18:34 CEST