[vlc-commits] misc: medialibrary: prefer loop over code duplication
Filip Roséen
git at videolan.org
Fri Jul 20 11:12:12 CEST 2018
vlc | branch: master | Filip Roséen <filip at atch.se> | Fri Jul 20 04:16:09 2018 +0200| [24f66ef2d701525cd5be94c81c86ca5d5f0943f3] | committer: Hugo Beauzée-Luyssen
misc: medialibrary: prefer loop over code duplication
(cherry picked from commit 90d5bb1cb6946628c869a9a2c44a65cbb5de2018)
Signed-off-by: Hugo Beauzée-Luyssen <hugo at beauzee.fr>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=24f66ef2d701525cd5be94c81c86ca5d5f0943f3
---
modules/misc/medialibrary/medialib.cpp | 23 +++++++++--------------
1 file changed, 9 insertions(+), 14 deletions(-)
diff --git a/modules/misc/medialibrary/medialib.cpp b/modules/misc/medialibrary/medialib.cpp
index 4c61025502..afbe30d5c2 100644
--- a/modules/misc/medialibrary/medialib.cpp
+++ b/modules/misc/medialibrary/medialib.cpp
@@ -38,6 +38,7 @@
#include <medialibrary/IPlaylist.h>
#include <sstream>
+#include <initializer_list>
class Logger : public medialibrary::ILogger
{
@@ -224,25 +225,19 @@ bool MediaLibrary::Start()
}
else
{
- auto videoFolder = vlc::wrap_cptr( config_GetUserDir( VLC_VIDEOS_DIR ) );
std::string varValue;
- if ( videoFolder != nullptr )
+ for( auto&& target : { VLC_VIDEOS_DIR, VLC_MUSIC_DIR } )
{
- auto mrl = std::string{ "file://" } + videoFolder.get();
- ml->discover( mrl );
- varValue = mrl;
- }
- auto musicFolder = vlc::wrap_cptr( config_GetUserDir( VLC_MUSIC_DIR ) );
- if ( musicFolder != nullptr )
- {
- auto mrl = std::string{ "file://" } + musicFolder.get();
+ auto folder = vlc::wrap_cptr( config_GetUserDir( target ) );
+ if( folder == nullptr )
+ continue;
+
+ auto mrl = std::string{ "file://" } + folder.get();
ml->discover( mrl );
- if ( varValue.empty() == false )
- varValue += ";";
- varValue += mrl;
+ varValue += ";" + mrl;
}
if ( varValue.empty() == false )
- config_PutPsz( "ml-folders", varValue.c_str() );
+ config_PutPsz( "ml-folders", varValue.c_str()+1 ); /* skip initial ';' */
}
m_ml = std::move( ml );
return true;
More information about the vlc-commits
mailing list