Skip to content

Commit 4b6ebcc

Browse files
committed
streams: remove confusing step variable
1 parent 02af9ac commit 4b6ebcc

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

main/streams/streams.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,8 +1534,6 @@ PHPAPI zend_string *_php_stream_copy_to_mem(php_stream *src, size_t maxlen, bool
15341534
ssize_t ret = 0;
15351535
char *ptr;
15361536
size_t len = 0, buflen;
1537-
int step = CHUNK_SIZE;
1538-
int min_room = CHUNK_SIZE / 4;
15391537
php_stream_statbuf ssbuf;
15401538
zend_string *result;
15411539

@@ -1578,31 +1576,32 @@ PHPAPI zend_string *_php_stream_copy_to_mem(php_stream *src, size_t maxlen, bool
15781576
* we can. Note that the stream may be filtered, in which case the stat
15791577
* result may be inaccurate, as the filter may inflate or deflate the
15801578
* number of bytes that we can read. In order to avoid an upsize followed
1581-
* by a downsize of the buffer, overestimate by the step size (which is
1579+
* by a downsize of the buffer, overestimate by the CHUNK_SIZE size (which is
15821580
* 8K). */
15831581
if (php_stream_stat(src, &ssbuf) == 0 && ssbuf.sb.st_size > 0) {
1584-
buflen = MAX(ssbuf.sb.st_size - src->position, 0) + step;
1582+
buflen = MAX(ssbuf.sb.st_size - src->position, 0) + CHUNK_SIZE;
15851583
if (maxlen > 0 && buflen > maxlen) {
15861584
buflen = maxlen;
15871585
}
15881586
} else {
1589-
buflen = step;
1587+
buflen = CHUNK_SIZE;
15901588
}
15911589

15921590
result = zend_string_alloc(buflen, persistent);
15931591
ptr = ZSTR_VAL(result);
15941592

1593+
const int min_room = CHUNK_SIZE / 4;
15951594
// TODO: Propagate error?
15961595
while ((ret = php_stream_read(src, ptr, buflen - len)) > 0) {
15971596
len += ret;
15981597
if (len + min_room >= buflen) {
15991598
if (maxlen == len) {
16001599
break;
16011600
}
1602-
if (maxlen > 0 && buflen + step > maxlen) {
1601+
if (maxlen > 0 && buflen + CHUNK_SIZE > maxlen) {
16031602
buflen = maxlen;
16041603
} else {
1605-
buflen += step;
1604+
buflen += CHUNK_SIZE;
16061605
}
16071606
result = zend_string_extend(result, buflen, persistent);
16081607
ptr = ZSTR_VAL(result) + len;

0 commit comments

Comments
 (0)