Return-Path: Delivered-To: apmail-apache-cvs-archive@apache.org Received: (qmail 50364 invoked by uid 500); 16 Oct 2000 22:10:46 -0000 Mailing-List: contact apache-cvs-help@apache.org; run by ezmlm Precedence: bulk Reply-To: new-httpd@apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list apache-cvs@apache.org Received: (qmail 50344 invoked by uid 500); 16 Oct 2000 22:10:43 -0000 Delivered-To: apmail-apache-2.0-cvs@apache.org Date: 16 Oct 2000 22:10:42 -0000 Message-ID: <20001016221042.50337.qmail@locus.apache.org> From: gregames@locus.apache.org To: apache-2.0-cvs@apache.org Subject: cvs commit: apache-2.0/src/main http_protocol.c gregames 00/10/16 15:10:42 Modified: src/main http_protocol.c Log: simplify bookkeeping in getline() to make it run a little faster, and (hopefully) be easier to understand in the future. Revision Changes Path 1.178 +11 -14 apache-2.0/src/main/http_protocol.c Index: http_protocol.c =================================================================== RCS file: /home/cvs/apache-2.0/src/main/http_protocol.c,v retrieving revision 1.177 retrieving revision 1.178 diff -u -r1.177 -r1.178 --- http_protocol.c 2000/10/16 20:08:14 1.177 +++ http_protocol.c 2000/10/16 22:10:41 1.178 @@ -1063,6 +1063,8 @@ static int getline(char *s, int n, conn_rec *c, int fold) { char *pos = s; + char *last_char; + char *beyond_buff = s + n; const char *temp; int retval; int total = 0; @@ -1093,7 +1095,8 @@ break; } - if (length <= n) { + last_char = pos + length - 1; + if (last_char < beyond_buff) { memcpy(pos, temp, length); AP_BUCKET_REMOVE(e); ap_bucket_destroy(e); @@ -1115,18 +1118,12 @@ * && (retval = e->read(e, ) * && ((next == ' ') || (next == '\t'))); */ - /* length is the number of characters read, not including NUL */ + pos = last_char; /* Point at the last character */ - n -= length; /* Keep track of how much of s is full */ - pos += (length - 1); /* and where s ends */ - total += length; /* and how long s has become */ - if (*pos == '\n') { /* Did we get a full line of input? */ if (pos > s && *(pos - 1) == '\r') { --pos; /* zap optional CR before LF */ - --total; - ++n; } /* @@ -1138,16 +1135,16 @@ while (pos > (s + 1) && (*(pos - 1) == ' ' || *(pos - 1) == '\t')) { --pos; /* trim extra trailing spaces or tabs */ - --total; /* but not one at the beginning of line */ - ++n; } - *pos = '\0'; - --total; - ++n; + *pos = '\0'; /* zap end of string */ + total = pos - s; break; } else { - pos++; /* bump past end of incomplete line */ + /* bump past last character read, + * and set total in case we bail before finding a LF + */ + total = ++pos - s; } } ap_brigade_destroy(b);