[vlc-commits] playlist: m3u speed up url lookup
Francois Cartegnie
git at videolan.org
Thu Sep 14 11:04:08 CEST 2017
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Tue Sep 12 17:37:29 2017 +0200| [a3bb5100efe6b5445867897607201477a5a13e68] | committer: Francois Cartegnie
playlist: m3u speed up url lookup
was pretty bad if junk file was starting with #
or all comments
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a3bb5100efe6b5445867897607201477a5a13e68
---
modules/demux/playlist/m3u.c | 67 +++++++++++++++++++++++++++++++-------------
1 file changed, 48 insertions(+), 19 deletions(-)
diff --git a/modules/demux/playlist/m3u.c b/modules/demux/playlist/m3u.c
index ea003d487e..d95440a948 100644
--- a/modules/demux/playlist/m3u.c
+++ b/modules/demux/playlist/m3u.c
@@ -150,33 +150,62 @@ int Import_M3U( vlc_object_t *p_this )
static bool ContainsURL(const uint8_t *p_peek, size_t i_peek)
{
- const uint8_t *p_peek_end = p_peek + i_peek;
- if( i_peek < 7 )
+ const char *ps = (const char *)p_peek;
+ const char *ps_end = (const char *) p_peek + i_peek;
+ const size_t i_max = sizeof( "https://" );
+ if( i_peek < i_max + 1 )
return false;
- while( p_peek + sizeof( "https://" ) < p_peek_end )
+ bool b_newline = true;
+ while( ps + i_max + 1 < ps_end )
{
- /* One line starting with a URL is enough */
- if( !strncasecmp( (const char *)p_peek, "http://", 7 ) ||
- !strncasecmp( (const char *)p_peek, "mms://", 6 ) ||
- !strncasecmp( (const char *)p_peek, "rtsp://", 7 ) ||
- !strncasecmp( (const char *)p_peek, "https://", 8 ) ||
- !strncasecmp( (const char *)p_peek, "ftp://", 6 ) ||
- !strncasecmp( (const char *)p_peek, "ftps://", 7 ) ||
- !strncasecmp( (const char *)p_peek, "ftpes://", 8 ) )
+ if( *ps <= 0 )
+ return false;
+
+ /* Goto next line */
+ if( *ps == '\n' )
{
- return true;
+ ps++;
+ b_newline = true;
+ continue;
}
- /* Comments and blank lines are ignored */
- else if( *p_peek != '#' && *p_peek != '\n' && *p_peek != '\r')
+
+ /* One line starting with a URL is enough */
+ if( b_newline )
{
- return false;
+ const char *ps_match = strnstr( ps, "://", i_max );
+ if(ps_match)
+ {
+ switch(ps_match - ps)
+ {
+ case 3:
+ if( !strncasecmp( ps, "mms", 3 ) ||
+ !strncasecmp( ps, "ftp", 3 ) )
+ return true;
+ break;
+ case 4:
+ if( !strncasecmp( ps, "http", 4 ) ||
+ !strncasecmp( ps, "rtsp", 4 ) ||
+ !strncasecmp( ps, "ftps", 4 ) )
+ return true;
+ break;
+ case 5:
+ if( !strncasecmp( ps, "https", 5 ) ||
+ !strncasecmp( ps, "ftpes", 5 ) )
+ return true;
+ default:
+ break;
+ }
+ }
+
+ /* Comments and blank lines are ignored */
+ if( *ps != '#' && *ps != '\n' && *ps != '\r')
+ return false;
+
+ b_newline = false;
}
- while( p_peek < p_peek_end && *p_peek != '\n' )
- p_peek++;
- if ( *p_peek == '\n' )
- p_peek++;
+ ps++;
}
return false;
}
More information about the vlc-commits
mailing list