From aa0e669802cce733d1d4914e821ebdd77fd372b8 Mon Sep 17 00:00:00 2001 From: Joerg Sonnenberger Date: Tue, 9 Nov 2004 08:47:36 +0000 Subject: [PATCH] Small speedups: - run.c: instead of counting string lenght and using strcpy afterwards anyway, use memmove - tran.c: use strdup instead of malloc + strcpy Submitted-by: Andreas Hauser --- usr.bin/awk/Makefile | 5 ++++- usr.bin/awk/patches/run.c.patch | 27 +++++++++++++++++++++++++++ usr.bin/awk/patches/tran.c.patch | 21 +++++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 usr.bin/awk/patches/run.c.patch create mode 100644 usr.bin/awk/patches/tran.c.patch diff --git a/usr.bin/awk/Makefile b/usr.bin/awk/Makefile index fc47f104aa..19e008131b 100644 --- a/usr.bin/awk/Makefile +++ b/usr.bin/awk/Makefile @@ -1,9 +1,12 @@ # $FreeBSD: src/usr.bin/awk/Makefile,v 1.9.2.1 2002/06/21 20:12:08 obrien Exp $ -# $DragonFly: src/usr.bin/awk/Makefile,v 1.6 2004/04/18 00:15:35 drhodus Exp $ +# $DragonFly: src/usr.bin/awk/Makefile,v 1.7 2004/11/09 08:47:36 joerg Exp $ AWKSRC= ${.CURDIR}/../../contrib/awk20040207 .PATH: ${AWKSRC} +PATCHES!= echo ${.CURDIR}/patches/*.patch +CONTRIBDIR= ${AWKSRC} + PROG= awk SRCS= awkgram.y b.c lex.c lib.c main.c parse.c proctab.c run.c tran.c ytab.h diff --git a/usr.bin/awk/patches/run.c.patch b/usr.bin/awk/patches/run.c.patch new file mode 100644 index 0000000000..83ec881470 --- /dev/null +++ b/usr.bin/awk/patches/run.c.patch @@ -0,0 +1,27 @@ +$DragonFly: src/usr.bin/awk/patches/run.c.patch,v 1.1 2004/11/09 08:47:36 joerg Exp $ + +Index: /run.c +=================================================================== +RCS file: /home/dcvs/src/contrib/awk20040207/run.c,v +retrieving revision 1.1.1.1 +diff -u -p -r1.1.1.1 run.c +--- run.c 17 Apr 2004 19:41:28 -0000 1.1.1.1 ++++ run.c 31 Oct 2004 03:58:23 -0000 +@@ -1145,13 +1145,13 @@ Cell *cat(Node **a, int q) /* a[0] cat a + getsval(x); + getsval(y); + n1 = strlen(x->sval); +- n2 = strlen(y->sval); +- s = (char *) malloc(n1 + n2 + 1); ++ n2 = strlen(y->sval) + 1; ++ s = (char *) malloc(n1 + n2); + if (s == NULL) + FATAL("out of space concatenating %.15s... and %.15s...", + x->sval, y->sval); +- strcpy(s, x->sval); +- strcpy(s+n1, y->sval); ++ memmove(s, x->sval, n1); ++ memmove(s+n1, y->sval, n2); + tempfree(y); + z = gettemp(); + z->sval = s; diff --git a/usr.bin/awk/patches/tran.c.patch b/usr.bin/awk/patches/tran.c.patch new file mode 100644 index 0000000000..b969bf9875 --- /dev/null +++ b/usr.bin/awk/patches/tran.c.patch @@ -0,0 +1,21 @@ +$DragonFly: src/usr.bin/awk/patches/tran.c.patch,v 1.1 2004/11/09 08:47:36 joerg Exp $ + +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 31 Oct 2004 03:18:48 -0000 +@@ -397,10 +397,9 @@ char *tostring(const char *s) /* make a + { + char *p; + +- p = (char *) malloc(strlen(s)+1); ++ p = strdup(s); + if (p == NULL) + FATAL("out of space in tostring on %s", s); +- strcpy(p, s); + return(p); + } + -- 2.35.2