Date: Fri, 2 Nov 2001 02:23:33 -0600 From: Alfred Perlstein <bright@mu.org> To: hackers@freebsd.org Subject: head(1) speedup Message-ID: <20011102022333.L15052@elvis.mu.org>
next in thread | raw e-mail | index | archive | help
can someone please check this out, it makes "head -n" about five
times faster. (also nukes a 'register', sorry :))
cvs diff: Diffing .
Index: head.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/head/head.c,v
retrieving revision 1.10
diff -c -r1.10 head.c
*** head.c 28 Aug 1999 01:01:58 -0000 1.10
--- head.c 2 Nov 2001 08:18:07 -0000
***************
*** 131,146 ****
void
head(fp, cnt)
FILE *fp;
! register int cnt;
{
! register int ch;
! while (cnt && (ch = getc(fp)) != EOF) {
! if (putchar(ch) == EOF)
! err(1, "stdout");
! if (ch == '\n')
! cnt--;
! }
}
void
--- 131,147 ----
void
head(fp, cnt)
FILE *fp;
! int cnt;
{
! char *cp;
! int error, readlen;
! while (cnt && (cp = fgetln(fp, &readlen)) != NULL) {
! error = fwrite(cp, sizeof(char), readlen, stdout);
! if (error != readlen)
! err(1, "stdout");
! cnt--;
! }
}
void
--
-Alfred Perlstein [alfred@freebsd.org]
'Instead of asking why a piece of software is using "1970s technology,"
start asking why software is ignoring 30 years of accumulated wisdom.'
http://www.morons.org/rants/gpl-harmful.php3
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?20011102022333.L15052>
