DragonFly BSD
DragonFly submit List (threaded) for 2004-10
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: A little speed up for awk


From: Joerg Sonnenberger <joerg@xxxxxxxxxxxxxxxxx>
Date: Sun, 31 Oct 2004 10:13:59 +0100

On Sat, Oct 30, 2004 at 09:34:54PM -0000, Andreas Hauser wrote:
> Index: tran.c
> ===================================================================
> RCS file: /home/dcvs/src/contrib/awk20040207/tran.c,v
> retrieving revision 1.1.1.1
> diff -u -p -r1.1.1.1 tran.c
> --- tran.c	17 Apr 2004 19:41:31 -0000	1.1.1.1
> +++ tran.c	1 Nov 2004 19:05:26 -0000
> @@ -396,11 +396,13 @@ char *getpssval(Cell *vp)     /* get str
>  char *tostring(const char *s)	/* make a copy of string s */
>  {
>  	char *p;
> +        size_t size;
>  
> -	p = (char *) malloc(strlen(s)+1);
> +	size = strlen(s) + 1;
> +	p = (char *) malloc(size);
>  	if (p == NULL)
>  		FATAL("out of space in tostring on %s", s);
> -	strcpy(p, s);
> +	bcopy(s, p, size);

p = strdup(s);
if (p == NULL)
	err("out of space in tostring on %s", s);

does the same and is shorter :)

Joerg

>  	return(p);
>  }
>  
> 



[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]