On Wed, Oct 7, 2015 at 2:47 PM, Julian Foad <[email protected]> wrote:
> Stefan wrote:
> > I guess the correct way of doing this is revert Ivan's
> > change and apply something like the attached patch.
> Ivan wrote:
> > Here is the patch that I wanted commit later. What do you think?
>
> I am not interested in reviewing any more patches that tweak just one
> of the implementations. If you (anybody) want to do something, please
> combine the two functions into one implementation, and then I will be
> interested in reviewing the (single) implementation.
>
Alright, here you go.
-- Stefan^2.
Index: subversion/libsvn_subr/stream.c
===================================================================
--- subversion/libsvn_subr/stream.c (revision 1706628)
+++ subversion/libsvn_subr/stream.c (working copy)
@@ -1488,7 +1488,7 @@
{
#define MIN_READ_SIZE 64
- apr_size_t to_read = 0;
+ apr_size_t to_read, gotten;
svn_stringbuf_t *text
= svn_stringbuf_create_ensure(len_hint ? len_hint : MIN_READ_SIZE,
result_pool);
@@ -1496,13 +1496,17 @@
do
{
to_read = text->blocksize - 1 - text->len;
- SVN_ERR(svn_stream_read_full(stream, text->data + text->len, &to_read));
- text->len += to_read;
+ if (to_read == 0)
+ {
+ svn_stringbuf_ensure(text, text->blocksize * 2);
+ to_read = text->blocksize - 1 - text->len;
+ }
- if (to_read && text->blocksize < text->len + MIN_READ_SIZE)
- svn_stringbuf_ensure(text, text->blocksize * 2);
+ gotten = to_read;
+ SVN_ERR(svn_stream_read_full(stream, text->data + text->len, &gotten));
+ text->len += gotten;
}
- while (to_read);
+ while (gotten == to_read);
text->data[text->len] = '\0';
*str = text;
@@ -1798,27 +1802,10 @@
apr_pool_t *result_pool,
apr_pool_t *scratch_pool)
{
- svn_stringbuf_t *work = svn_stringbuf_create_ensure(SVN__STREAM_CHUNK_SIZE,
- result_pool);
- char *buffer = apr_palloc(scratch_pool, SVN__STREAM_CHUNK_SIZE);
+ svn_stringbuf_t buffer;
+ SVN_ERR(svn_stringbuf_from_stream(&buffer, stream, 0, scratch_pool));
+ *result = svn_string_ncreate(buffer.data, buffer.len, result_pool);
- while (1)
- {
- apr_size_t len = SVN__STREAM_CHUNK_SIZE;
-
- SVN_ERR(svn_stream_read_full(stream, buffer, &len));
- svn_stringbuf_appendbytes(work, buffer, len);
-
- if (len < SVN__STREAM_CHUNK_SIZE)
- break;
- }
-
- SVN_ERR(svn_stream_close(stream));
-
- *result = apr_palloc(result_pool, sizeof(**result));
- (*result)->data = work->data;
- (*result)->len = work->len;
-
return SVN_NO_ERROR;
}