Date: Fri, 30 Jul 1999 23:56:26 +0900 From: "Daniel C. Sobral" <dcs@newsguy.com> To: Dag-Erling Smorgrav <des@flood.ping.uio.no> Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: replacing grep(1) Message-ID: <37A1BD1A.59DF842E@newsguy.com> References: <19990729182229.E24296@mad> <Pine.GSO.4.10.9907291856100.11776-100000@rac9.wam.umd.edu> <19990729164533.36798@hydrogen.fircrest.net> <xzpyafy1d53.fsf@flood.ping.uio.no> <xzpwvvi1czq.fsf@flood.ping.uio.no>
next in thread | previous in thread | raw e-mail | index | archive | help
Dag-Erling Smorgrav wrote:
>
> To be precise, I experience a 30% decrease in system time and a 100%
> increase in user time when I use RE_STARTEND and eliminate the
> malloc() / memcpy() calls in procfile().
Could you please test my patch that removes malloc() but bot
memcpy()? Here it is again, though against an old version:
--- util.c.orig Thu Jul 29 19:14:17 1999
+++ util.c Thu Jul 29 20:49:16 1999
@@ -107,6 +107,8 @@
ln.file = fn;
ln.line_no = 0;
+ ln.bufsize = 81; /* Magical constants, yeah! */
+ ln.dat = grep_malloc(81);
linesqueued = 0;
if (Bflag > 0)
@@ -115,11 +117,14 @@
ln.off = grep_tell();
if ((tmp = grep_getln(&ln.len)) == NULL)
break;
- ln.dat = grep_malloc(ln.len + 1);
+ if (ln.bufsize < ln.len + 1)
+ ln.dat = grep_realloc(ln.dat, ln.len + 1);
memcpy(ln.dat, tmp, ln.len);
- ln.dat[ln.len] = 0;
if (ln.len > 0 && ln.dat[ln.len - 1] == '\n')
ln.dat[--ln.len] = 0;
+ else
+ ln.dat[ln.len] = 0;
+
ln.line_no++;
z = tail;
@@ -127,9 +132,9 @@
enqueue(&ln);
linesqueued++;
}
- free(ln.dat);
c += t;
}
+ free(ln.dat);
if (Bflag > 0)
clearqueue();
grep_close();
--- grep.h.orig Thu Jul 29 20:47:52 1999
+++ grep.h Thu Jul 29 20:48:34 1999
@@ -35,6 +35,7 @@
typedef struct {
size_t len;
+ size_t bufsize;
int line_no;
int off;
char *file;
--
Daniel C. Sobral (8-DCS)
dcs@newsguy.com
dcs@freebsd.org
"Is it true that you're a millionaire's son who never worked a day
in your life?"
"Yeah, I guess so."
"Lemme tell you, son, you ain't missed a thing."
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?37A1BD1A.59DF842E>
