[vlc-commits] qt: reduce the number of calls on the UI thread on item removed in NetworkMediaModel
Pierre Lamot
git at videolan.org
Fri Jan 24 11:37:53 CET 2020
vlc | branch: master | Pierre Lamot <pierre at videolabs.io> | Mon Jan 20 14:23:22 2020 +0100| [5dc68f674f3c7ee9bed5264546b5d9ffc43e35c4] | committer: Thomas Guillem
qt: reduce the number of calls on the UI thread on item removed in NetworkMediaModel
Signed-off-by: Thomas Guillem <thomas at gllm.fr>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5dc68f674f3c7ee9bed5264546b5d9ffc43e35c4
---
modules/gui/qt/network/networkmediamodel.cpp | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/modules/gui/qt/network/networkmediamodel.cpp b/modules/gui/qt/network/networkmediamodel.cpp
index 9cb75433c7..7f6876cf11 100644
--- a/modules/gui/qt/network/networkmediamodel.cpp
+++ b/modules/gui/qt/network/networkmediamodel.cpp
@@ -296,33 +296,37 @@ void NetworkMediaModel::onItemRemoved( MediaSourcePtr,
input_item_node_t *const children[],
size_t count )
{
+ std::vector<InputItemPtr> itemList;
+ itemList.reserve( count );
for ( auto i = 0u; i < count; ++i )
- {
- InputItemPtr p_item { children[i]->p_item };
- QMetaObject::invokeMethod(this, [this, p_item=std::move(p_item)]() {
+ itemList.emplace_back( children[i]->p_item );
+
+ QMetaObject::invokeMethod(this, [this, itemList=std::move(itemList)]() {
+ for (auto p_item : itemList)
+ {
QUrl itemUri = QUrl::fromEncoded(p_item->psz_uri);
auto it = std::find_if( begin( m_items ), end( m_items ), [&](const Item& i) {
return QString::compare( qfu(p_item->psz_name), i.name, Qt::CaseInsensitive ) == 0 &&
itemUri.scheme() == i.mainMrl.scheme();
});
if ( it == end( m_items ) )
- return;
+ continue;
auto mrlIt = std::find_if( begin( (*it).mrls ), end( (*it).mrls),
[itemUri]( const QUrl& mrl ) {
return mrl == itemUri;
});
if ( mrlIt == end( (*it).mrls ) )
- return;
+ continue;
(*it).mrls.erase( mrlIt );
if ( (*it).mrls.empty() == false )
- return;
+ continue;
auto idx = std::distance( begin( m_items ), it );
beginRemoveRows({}, idx, idx );
m_items.erase( it );
endRemoveRows();
- });
- }
+ }
+ }, Qt::QueuedConnection);
}
void NetworkMediaModel::onItemPreparseEnded(MediaSourcePtr, input_item_node_t*, enum input_item_preparse_status)
More information about the vlc-commits
mailing list