<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta name="generator" content="pandoc" />
<title></title>
<style type="text/css">code{white-space: pre;}</style>
</head>
<body>
<p>Hi Hugo,</p>
<p>On 2017-03-17 11:08, Hugo Beauzée-Luyssen wrote:</p>
<blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;color:#500050">
<pre><code> On Fri, Mar 17, 2017, at 03:22 AM, Filip Roséen wrote:</code></pre>
<blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;color:#500050">
<pre><code> +int
+stream_extractor_AttachParsed( stream_t** source, char const* data,
+ char const** out_extra )
+{
+ vlc_array_t identifiers;
+
+ if( mrl_FragmentSplit( &identifiers, out_extra, data ) )
+ return VLC_EGENERIC;
+
+ while( vlc_array_count( &identifiers ) )
+ {
+ char* id = vlc_array_item_at_index( &identifiers, 0 );
+
+ if( vlc_stream_extractor_Attach( source, id, NULL ) )
+ break;
+
+ vlc_array_remove( &identifiers, 0 );
+ free( id );
+ }
+
+ size_t remaining = vlc_array_count( &identifiers );
+
+ for( size_t i = 0; i < remaining; ++i )
+ free( vlc_array_item_at_index( &identifiers, i ) );
+ vlc_array_clear( &identifiers );
+
+ if( remaining == 0 )
+ {
+ vlc_stream_extractor_Attach( source, NULL, NULL );
+ return VLC_SUCCESS;
+ }
+
+ return remaining == 0 ? VLC_SUCCESS : VLC_EGENERIC;
+}</code></pre>
</blockquote>
<pre><code> Couldn't this be written in a way that has no vlc_array_remove and a
single unconditional vlc_array_clean?</code></pre>
</blockquote>
<p>Sure, it could - I simply wrote it the way proposed as shrinking and moving the underlying storage is not exactly expensive in the path taken, nor would this function normally be called with a trillion elements in <code>identifiers</code>.</p>
<p>I found it easier to read using <code>while</code> instead of <code>for</code>, but please see attached patch for an updated one (that also removes a trailing if-branch that should not be part of the function, the removal was accidentally rebased upon a later commit instead if this one).</p>
<blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;color:#500050">
<pre><code> You should be able to guess if some items weren't processed if you
index is < vlc_array_count. This would prevent quite a bunch of
reallocs/memmove</code></pre>
</blockquote>
<p>Correct, but there’s strictly speaking no need to guess <code>;-)</code>.</p>
<p>Thanks,<br />
Filip Roséen</p>
<blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;color:#500050">
<blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;color:#500050">
<pre><code> +
char*
vlc_stream_extractor_CreateMRL( stream_directory_t* directory,
char const* subentry )</code></pre>
</blockquote>
</blockquote>
</body>
</html>