wez Tue Mar 18 09:41:47 2003 EDT Modified files: (Branch: PHP_4_3) /php4/main streams.c Log: Fix my 64-bit casting fix. MFH Fix for #22721 - poor performance for file() on systems without mmap support. Index: php4/main/streams.c diff -u php4/main/streams.c:1.125.2.40 php4/main/streams.c:1.125.2.41 --- php4/main/streams.c:1.125.2.40 Mon Mar 17 17:26:51 2003 +++ php4/main/streams.c Tue Mar 18 09:41:46 2003 @@ -20,7 +20,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: streams.c,v 1.125.2.40 2003/03/17 22:26:51 iliaa Exp $ */ +/* $Id: streams.c,v 1.125.2.41 2003/03/18 14:41:46 wez Exp $ */ #define _GNU_SOURCE #include "php.h" @@ -1075,6 +1075,7 @@ size_t len = 0, max_len; int step = CHUNK_SIZE; int min_room = CHUNK_SIZE / 4; + php_stream_statbuf ssbuf; #if HAVE_MMAP int srcfd; #endif @@ -1133,7 +1134,20 @@ } #endif - ptr = *buf = pemalloc_rel_orig(step, persistent); + /* avoid many reallocs by allocating a good sized chunk to begin with, if we can. + * Note that the stream may be filtered, in which case the stat result may be inaccurate, + * as the filter may inflate or deflate the number of bytes that we can read. + * In order to avoid an upsize followed by a downsize of the buffer, overestimate by the + * step size (which is 2K). + * */ + if (php_stream_stat(src, &ssbuf) == 0 && ssbuf.sb.st_size > 0) { + max_len = ssbuf.sb.st_size + step; + } else { + max_len = step; + } + + ptr = *buf = pemalloc_rel_orig(max_len, persistent); + max_len = step; while((ret = php_stream_read(src, ptr, max_len - len))) { @@ -1536,7 +1550,7 @@ } if (ret) { fflush(data->file); - *(int**)ret = fd; + *(int*)ret = fd; } return SUCCESS; default:
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php