lbarnaud                Thu Mar 19 17:55:10 2009 UTC

  Modified files:              (Branch: PHP_5_3)
    /php-src/main/streams       streams.c 
  Log:
  MFH: Better fix for #44607. Fixes #47487 (php_stream_fill_read_buffer()
  performance degraded after fix of bug 44607).
  
  
http://cvs.php.net/viewvc.cgi/php-src/main/streams/streams.c?r1=1.82.2.6.2.18.2.23&r2=1.82.2.6.2.18.2.24&diff_format=u
Index: php-src/main/streams/streams.c
diff -u php-src/main/streams/streams.c:1.82.2.6.2.18.2.23 
php-src/main/streams/streams.c:1.82.2.6.2.18.2.24
--- php-src/main/streams/streams.c:1.82.2.6.2.18.2.23   Thu Jan  8 18:46:00 2009
+++ php-src/main/streams/streams.c      Thu Mar 19 17:55:10 2009
@@ -19,7 +19,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: streams.c,v 1.82.2.6.2.18.2.23 2009/01/08 18:46:00 felipe Exp $ */
+/* $Id: streams.c,v 1.82.2.6.2.18.2.24 2009/03/19 17:55:10 lbarnaud Exp $ */
 
 #define _GNU_SOURCE
 #include "php.h"
@@ -540,16 +540,16 @@
                efree(chunk_buf);
 
        } else {
-               /* reduce buffer memory consumption if possible, to avoid a 
realloc */
-               if (stream->readbuf && stream->readbuflen - stream->writepos < 
stream->chunk_size) {
-                       memmove(stream->readbuf, stream->readbuf + 
stream->readpos, stream->readbuflen - stream->readpos);
-                       stream->writepos -= stream->readpos;
-                       stream->readpos = 0;
-               }
                /* is there enough data in the buffer ? */
-               while (stream->writepos - stream->readpos < (off_t)size) {
+               if (stream->writepos - stream->readpos < (off_t)size) {
                        size_t justread = 0;
-                       size_t toread;
+
+                       /* reduce buffer memory consumption if possible, to 
avoid a realloc */
+                       if (stream->readbuf && stream->readbuflen - 
stream->writepos < stream->chunk_size) {
+                               memmove(stream->readbuf, stream->readbuf + 
stream->readpos, stream->readbuflen - stream->readpos);
+                               stream->writepos -= stream->readpos;
+                               stream->readpos = 0;
+                       }
 
                        /* grow the buffer if required
                         * TODO: this can fail for persistent streams */
@@ -559,17 +559,13 @@
                                                stream->is_persistent);
                        }
 
-                       toread = stream->readbuflen - stream->writepos;
                        justread = stream->ops->read(stream, stream->readbuf + 
stream->writepos,
-                                       toread
+                                       stream->readbuflen - stream->writepos
                                        TSRMLS_CC);
 
                        if (justread != (size_t)-1) {
                                stream->writepos += justread;
                        }
-                       if (stream->eof || justread != toread) {
-                               break;
-                       }
                }
        }
 }
@@ -868,10 +864,25 @@
 PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t 
*returned_len, char *delim, size_t delim_len TSRMLS_DC)
 {
        char *e, *buf;
-       size_t toread;
+       size_t toread, len;
        int skip = 0;
 
-       php_stream_fill_read_buffer(stream, maxlen TSRMLS_CC);
+       len = stream->writepos - stream->readpos;
+
+       while (len < maxlen) {
+
+               size_t just_read;
+               toread = MIN(maxlen - len, stream->chunk_size);
+
+               php_stream_fill_read_buffer(stream, len + toread TSRMLS_CC);
+
+               just_read = (stream->writepos - stream->readpos) - len;
+               len += just_read;
+
+               if (just_read < toread) {
+                       break;
+               }
+       }
 
        if (delim_len == 0 || !delim) {
                toread = maxlen;



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to