From owner-freebsd-hackers Fri Nov 2 0:23:49 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from elvis.mu.org (elvis.mu.org [216.33.66.196]) by hub.freebsd.org (Postfix) with ESMTP id D9E0537B401 for ; Fri, 2 Nov 2001 00:23:38 -0800 (PST) Received: by elvis.mu.org (Postfix, from userid 1192) id 8A10581D05; Fri, 2 Nov 2001 02:23:33 -0600 (CST) Date: Fri, 2 Nov 2001 02:23:33 -0600 From: Alfred Perlstein To: hackers@freebsd.org Subject: head(1) speedup Message-ID: <20011102022333.L15052@elvis.mu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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