Date: Fri, 9 Apr 1999 19:36:50 -0700 (PDT) From: wolman@cs.washington.edu To: freebsd-gnats-submit@freebsd.org Subject: misc/11052: [PATCH] performance bug fix to fgets() routine Message-ID: <19990410023650.2B10514EFF@hub.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 11052 >Category: misc >Synopsis: [PATCH] performance bug fix to fgets() routine >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Fri Apr 9 19:40:00 PDT 1999 >Closed-Date: >Last-Modified: >Originator: Alec Wolman >Release: 3.1 >Organization: UW, CSE Department >Environment: FreeBSD miles.cs.washington.edu 3.1-19990403-STABLE FreeBSD 3.1-19990403-STABLE #0: Sun Apr 4 23:54:44 PDT 1999 wolman@miles.cs.washington.edu:/usr/src/sys/compile/MILES i386 >Description: The fgets routine touches all the string data twice, once with a call to the memchr() routine, and then again with a call to memcpy(). Using memccpy() eliminates this problem. >How-To-Repeat: N/A. >Fix: The following patch fixes the problem. It have tested the patch, and the measured the performance improvement for lines whose length was 130 characters on average. The new version is 15% faster on my P6/200. I would be happy to email the diff to anyone who is interested, since cut & paste destroys the TABs. --- fgets.c.orig Sat Apr 11 00:40:43 1998 +++ fgets.c Fri Apr 9 19:23:11 1999 @@ -59,8 +59,8 @@ register FILE *fp; { register size_t len; - register char *s; - register unsigned char *p, *t; + register char *s,*t; + register unsigned char *p; if (n <= 0) /* sanity check */ return (NULL); @@ -93,19 +93,17 @@ */ if (len > n) len = n; - t = memchr((void *)p, '\n', len); + t = memccpy((void *)s, (void *)p, '\n', len); if (t != NULL) { - len = ++t - p; + len = t - s; fp->_r -= len; - fp->_p = t; - (void)memcpy((void *)s, (void *)p, len); + fp->_p += len; s[len] = 0; FUNLOCKFILE(fp); return (buf); } fp->_r -= len; fp->_p += len; - (void)memcpy((void *)s, (void *)p, len); s += len; n -= len; } >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19990410023650.2B10514EFF>