[vlc-devel] [PATCH 8/8] stream_ReadLine: probe data exponentially instead of linearly

Pierre Ynard linkfanel at yahoo.fr
Wed Oct 21 05:34:29 CEST 2020


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.


diff --git a/src/input/stream.c b/src/input/stream.c
index 6d6b263..e19aeb6 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;
 
-- 
Pierre Ynard
"Une âme dans un corps, c'est comme un dessin sur une feuille de papier."


More information about the vlc-devel mailing list