[vlc-devel] commit: asx.c: change reallocating to doupling instead of adding just 1024 (Ilkka Ollakka )

git version control git at videolan.org
Tue Oct 13 10:53:36 CEST 2009


vlc | branch: master | Ilkka Ollakka <ileoo at videolan.org> | Mon Oct 12 16:33:12 2009 +0300| [1acdfadc2a9500b29b7bb73ef3100a7fbeeed955] | committer: Ilkka Ollakka 

asx.c: change reallocating to doupling instead of adding just 1024

Also change comparing stream size from (<=0 && < 16384) to (<=0 && >16384)

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

 modules/demux/playlist/asx.c |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/modules/demux/playlist/asx.c b/modules/demux/playlist/asx.c
index dc865bf..9cfb7a4 100644
--- a/modules/demux/playlist/asx.c
+++ b/modules/demux/playlist/asx.c
@@ -240,8 +240,8 @@ static int Demux( demux_t *p_demux )
     if( p_sys->i_data_len < 0 )
     {
         int64_t i_pos = 0;
-        p_sys->i_data_len = stream_Size( p_demux->s ) +1; /* This is a cheat to prevent unnecessary realloc */
-        if( p_sys->i_data_len <= 0 && p_sys->i_data_len < 16384 ) p_sys->i_data_len = 1024;
+        p_sys->i_data_len = stream_Size( p_demux->s ) + 1; /* This is a cheat to prevent unnecessary realloc */
+        if( p_sys->i_data_len <= 0 || p_sys->i_data_len > 16384 ) p_sys->i_data_len = 1024;
         p_sys->psz_data = malloc( p_sys->i_data_len +1);
 
         /* load the complete file */
@@ -252,10 +252,9 @@ static int Demux( demux_t *p_demux )
 
             if( i_read < p_sys->i_data_len - i_pos ) break; /* Done */
 
-            /* XXX this looks fishy and inefficient */
             i_pos += i_read;
-            p_sys->i_data_len += 1024;
-            p_sys->psz_data = realloc( p_sys->psz_data, p_sys->i_data_len * sizeof( char * ) +1 );
+            p_sys->i_data_len <<= 1 ;
+            p_sys->psz_data = realloc( p_sys->psz_data, p_sys->i_data_len * sizeof( char * ) + 1 );
         }
         if( p_sys->i_data_len <= 0 ) return -1;
     }




More information about the vlc-devel mailing list