[vlc-commits] stream_ReadLine: probe data exponentially instead of linearly

Pierre Ynard git at videolan.org
Tue Oct 27 09:10:20 CET 2020


vlc | branch: master | Pierre Ynard <linkfanel at yahoo.fr> | Tue Oct 27 09:01:25 2020 +0100| [aa4996021d00ee7fc5ce1516316511ee96005966] | committer: Pierre Ynard

stream_ReadLine: probe data exponentially instead of linearly

This reduces the number of buffer reallocations performed for long
lines, turning the function's complexity from quadratic to linear. The
line length limit remains unchanged.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=aa4996021d00ee7fc5ce1516316511ee96005966
---

 src/input/stream.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/input/stream.c b/src/input/stream.c
index 45a724afab..77c8cf0e4c 100644
--- a/src/input/stream.c
+++ b/src/input/stream.c
@@ -245,9 +245,11 @@ char *vlc_stream_ReadLine( stream_t *s )
 
     for( ;; )
     {
+        size_t i_peek = i_line == 0 ? STREAM_PROBE_LINE
+                                    : __MIN( i_line * 2, STREAM_LINE_MAX );
+
         /* Probe more data */
-        ssize_t i_data = vlc_stream_Peek( s, &p_data,
-                                          i_line + STREAM_PROBE_LINE );
+        ssize_t i_data = vlc_stream_Peek( s, &p_data, i_peek );
         if( i_data <= 0 )
             return NULL;
 



More information about the vlc-commits mailing list