subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From i...@apache.org
Subject svn commit: r1710066 - /subversion/trunk/subversion/libsvn_subr/stream.c
Date Thu, 22 Oct 2015 17:09:38 GMT
Author: ivan
Date: Thu Oct 22 17:09:38 2015
New Revision: 1710066

URL: http://svn.apache.org/viewvc?rev=1710066&view=rev
Log:
* subversion/libsvn_subr/stream.c
  (): Include svn_sorts.h.
  (svn_stringbuf_from_stream): Optimize memory usage a bit and avoid
   svn_stream_read_full() call after we got partial read.

Modified:
    subversion/trunk/subversion/libsvn_subr/stream.c

Modified: subversion/trunk/subversion/libsvn_subr/stream.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/stream.c?rev=1710066&r1=1710065&r2=1710066&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/stream.c (original)
+++ subversion/trunk/subversion/libsvn_subr/stream.c Thu Oct 22 17:09:38 2015
@@ -42,6 +42,7 @@
 #include "svn_checksum.h"
 #include "svn_path.h"
 #include "svn_private_config.h"
+#include "svn_sorts.h"
 #include "private/svn_atomic.h"
 #include "private/svn_error_private.h"
 #include "private/svn_eol_private.h"
@@ -1487,22 +1488,24 @@ svn_stringbuf_from_stream(svn_stringbuf_
                           apr_pool_t *result_pool)
 {
 #define MIN_READ_SIZE 64
-
-  apr_size_t to_read = 0;
   svn_stringbuf_t *text
-    = svn_stringbuf_create_ensure(len_hint + MIN_READ_SIZE,
+    = svn_stringbuf_create_ensure(MAX(len_hint + 1, MIN_READ_SIZE),
                                   result_pool);
 
-  do
+  while(TRUE)
     {
-      to_read = text->blocksize - 1 - text->len;
-      SVN_ERR(svn_stream_read_full(stream, text->data + text->len, &to_read));
-      text->len += to_read;
+      apr_size_t to_read = text->blocksize - 1 - text->len;
+      apr_size_t actually_read = to_read;
+
+      SVN_ERR(svn_stream_read_full(stream, text->data + text->len, &actually_read));
+      text->len += actually_read;
+
+      if (actually_read < to_read)
+        break;
 
-      if (to_read && text->blocksize < text->len + MIN_READ_SIZE)
+      if (text->blocksize < text->len + MIN_READ_SIZE)
         svn_stringbuf_ensure(text, text->blocksize * 2);
     }
-  while (to_read);
 
   text->data[text->len] = '\0';
   *str = text;



Mime
View raw message