diff --git a/retroshare-gui/src/gui/Circles/CreateCircleDialog.cpp b/retroshare-gui/src/gui/Circles/CreateCircleDialog.cpp index 59b0da95d..3733c0f1a 100644 --- a/retroshare-gui/src/gui/Circles/CreateCircleDialog.cpp +++ b/retroshare-gui/src/gui/Circles/CreateCircleDialog.cpp @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -696,34 +697,32 @@ void CreateCircleDialog::loadIdentities() { RsThread::async([this]() { - std::list ids_meta; + std::list ids_meta; if(!rsIdentity->getIdentitiesSummaries(ids_meta)) { - std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve identities ids for all identities" << std::endl; + RS_ERR("failed to retrieve identities ids for all identities"); return; - } - std::set ids; + } - for(auto& meta:ids_meta) - ids.insert(RsGxsId(meta.mGroupId)) ; + std::set ids; + for(auto& meta:ids_meta) ids.insert(RsGxsId(meta.mGroupId)); - std::vector id_groups; - - if(!rsIdentity->getIdentitiesInfo(ids,id_groups)) + auto id_groups = std::make_unique>(); + if(!rsIdentity->getIdentitiesInfo(ids, *id_groups)) { - std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve identities group info for all identities" << std::endl; + RS_ERR("failed to retrieve identities group info for all identities"); return; - } + } - RsQThreadUtils::postToObject( [id_groups,this]() + RsQThreadUtils::postToObject( + [id_groups = std::move(id_groups), this]() { /* Here it goes any code you want to be executed on the Qt Gui * thread, for example to update the data model with new information * after a blocking call to RetroShare API complete */ - fillIdentitiesList(id_groups) ; - + fillIdentitiesList(*id_groups); }, this ); }); diff --git a/retroshare-gui/src/gui/Identity/IdDialog.cpp b/retroshare-gui/src/gui/Identity/IdDialog.cpp index 1a585d532..d49e558ec 100644 --- a/retroshare-gui/src/gui/Identity/IdDialog.cpp +++ b/retroshare-gui/src/gui/Identity/IdDialog.cpp @@ -47,6 +47,7 @@ #include "util/misc.h" #include "util/QtVersion.h" #include "util/rstime.h" +#include "util/rsdebug.h" #include "retroshare/rsgxsflags.h" #include "retroshare/rsmsgs.h" @@ -55,6 +56,7 @@ #include #include +#include /****** * #define ID_DEBUG 1 @@ -506,21 +508,24 @@ void IdDialog::updateCircles() std::cerr << "Retrieving post data for post " << mThreadId << std::endl; #endif - std::list circle_metas ; + /* This can be big so use a smart pointer to just copy the pointer + * instead of copying the whole list accross the lambdas */ + auto circle_metas = std::make_unique>(); - if(!rsGxsCircles->getCirclesSummaries(circle_metas)) + if(!rsGxsCircles->getCirclesSummaries(*circle_metas)) { - std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve circles group info list" << std::endl; + RS_ERR("failed to retrieve circles group info list"); return; - } + } - RsQThreadUtils::postToObject( [circle_metas,this]() + RsQThreadUtils::postToObject( + [circle_metas = std::move(circle_metas), this]() { /* Here it goes any code you want to be executed on the Qt Gui * thread, for example to update the data model with new information * after a blocking call to RetroShare API complete */ - loadCircles(circle_metas); + loadCircles(*circle_metas); }, this ); @@ -1305,19 +1310,17 @@ void IdDialog::updateIdList() return; } - std::map ids_set; + auto ids_set = std::make_unique>(); + for(auto it(groups.begin()); it!=groups.end(); ++it) + (*ids_set)[(*it).mMeta.mGroupId] = *it; - for(auto it(groups.begin());it!=groups.end();++it) - ids_set[(*it).mMeta.mGroupId] = *it; - - RsQThreadUtils::postToObject( [ids_set,this]() + RsQThreadUtils::postToObject( + [ids_set = std::move(ids_set), this] () { /* Here it goes any code you want to be executed on the Qt Gui * thread, for example to update the data model with new information * after a blocking call to RetroShare API complete */ - - loadIdentities(ids_set); - + loadIdentities(*ids_set); }, this ); }); diff --git a/retroshare-gui/src/gui/Identity/IdEditDialog.cpp b/retroshare-gui/src/gui/Identity/IdEditDialog.cpp index bb1ee139a..0f432ba2d 100644 --- a/retroshare-gui/src/gui/Identity/IdEditDialog.cpp +++ b/retroshare-gui/src/gui/Identity/IdEditDialog.cpp @@ -210,8 +210,8 @@ void IdEditDialog::setupExistingId(const RsGxsGroupId& keyId) RsThread::async([this,keyId]() { std::vector datavector; - - bool res = rsIdentity->getIdentitiesInfo(std::set({(RsGxsId)keyId}),datavector); + bool res = rsIdentity->getIdentitiesInfo( + std::set({(RsGxsId)keyId}), datavector ); RsQThreadUtils::postToObject( [this,keyId,res,datavector]() { diff --git a/retroshare-gui/src/gui/common/FriendSelectionWidget.cpp b/retroshare-gui/src/gui/common/FriendSelectionWidget.cpp index fa5c439f1..4043fe424 100644 --- a/retroshare-gui/src/gui/common/FriendSelectionWidget.cpp +++ b/retroshare-gui/src/gui/common/FriendSelectionWidget.cpp @@ -36,6 +36,7 @@ #include #include +#include #define COLUMN_NAME 0 #define COLUMN_CHECK 0 @@ -250,24 +251,21 @@ void FriendSelectionWidget::loadIdentities() if(!rsIdentity->getIdentitiesSummaries(ids_meta)) { - std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve identities group info for all identities" << std::endl; + RS_ERR("failed to retrieve identities group info for all identities"); return; - } - std::vector ids; + } - for(auto& meta:ids_meta) - ids.push_back(meta.mGroupId) ; + auto ids = std::make_unique>(); + for(auto& meta: ids_meta) ids->push_back(meta.mGroupId); - RsQThreadUtils::postToObject( [ids,this]() + RsQThreadUtils::postToObject( + [ids = std::move(ids), this]() { - /* Here it goes any code you want to be executed on the Qt Gui - * thread, for example to update the data model with new information - * after a blocking call to RetroShare API complete */ - - gxsIds = ids; // we do that is the GUI thread. Dont try it on another thread! - - fillList() ; - + // We do that is the GUI thread. Dont try it on another thread! + gxsIds = *ids; + /* TODO: To furter optimize away a copy gxsIds could be a unique_ptr + * too */ + fillList(); }, this ); }); } diff --git a/retroshare-gui/src/gui/statistics/GxsTransportStatistics.cpp b/retroshare-gui/src/gui/statistics/GxsTransportStatistics.cpp index 4f1605c46..c258cb4bc 100644 --- a/retroshare-gui/src/gui/statistics/GxsTransportStatistics.cpp +++ b/retroshare-gui/src/gui/statistics/GxsTransportStatistics.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -463,24 +464,25 @@ void GxsTransportStatistics::loadGroups() #ifdef DEBUG_FORUMS std::cerr << "Retrieving post data for post " << mThreadId << std::endl; #endif - std::map stats; + auto stats = std::make_unique< + std::map >(); - if(!rsGxsTrans->getGroupStatistics(stats)) - { - RsErr() << "Cannot retrieve group statistics in GxsTransportStatistics" << std::endl; - return; - } + if(!rsGxsTrans->getGroupStatistics(*stats)) + { + RS_ERR("Cannot retrieve group statistics in GxsTransportStatistics"); + return; + } - RsQThreadUtils::postToObject( [stats,this]() + RsQThreadUtils::postToObject( + [stats = std::move(stats), this]() { /* Here it goes any code you want to be executed on the Qt Gui * thread, for example to update the data model with new information * after a blocking call to RetroShare API complete */ - mGroupStats = stats; - - updateContent(); - + // TODO: consider making mGroupStats an unique_ptr to avoid copying + mGroupStats = *stats; + updateContent(); mStateHelper->setLoading(GXSTRANS_GROUP_META, false); }, this ); diff --git a/retroshare-gui/src/util/qtthreadsutils.h b/retroshare-gui/src/util/qtthreadsutils.h index 155b71b7e..1c377b35d 100644 --- a/retroshare-gui/src/util/qtthreadsutils.h +++ b/retroshare-gui/src/util/qtthreadsutils.h @@ -1,7 +1,7 @@ /******************************************************************************* * util/qthreadutils.h * * * - * Copyright (C) 2018 Gioacchino Mazzurco * + * Copyright (C) 2018-2020 Gioacchino Mazzurco * * * * This program is free software: you can redistribute it and/or modify * * it under the terms of the GNU Affero General Public License as * @@ -27,7 +27,9 @@ #include #include + #include +#include namespace RsQThreadUtils { @@ -44,7 +46,7 @@ void postToObject(F &&fun, QObject *obj = qApp) QObject src; auto type = obj->metaObject(); QObject::connect( &src, &QObject::destroyed, obj, - [fun, type, obj] + [fun = std::move(fun), type, obj] { // ensure that the object is not being destructed if (obj->metaObject()->inherits(type)) fun();