mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-12 07:59:29 -05:00
Merge pull request #2018 from G10h4ck/memory_optimization
Reduce memory usage due to copying in RsQThreadUtils::postToObject
This commit is contained in:
commit
638ef80788
@ -24,6 +24,7 @@
|
||||
#include <QMenu>
|
||||
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
|
||||
#include <retroshare/rspeers.h>
|
||||
#include <retroshare/rsidentity.h>
|
||||
@ -700,30 +701,28 @@ void CreateCircleDialog::loadIdentities()
|
||||
|
||||
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<RsGxsId> ids;
|
||||
for(auto& meta:ids_meta) ids.insert(RsGxsId(meta.mGroupId));
|
||||
|
||||
for(auto& meta:ids_meta)
|
||||
ids.insert(RsGxsId(meta.mGroupId)) ;
|
||||
|
||||
std::vector<RsGxsIdGroup> id_groups;
|
||||
|
||||
if(!rsIdentity->getIdentitiesInfo(ids,id_groups))
|
||||
auto id_groups = std::make_unique<std::vector<RsGxsIdGroup>>();
|
||||
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 );
|
||||
});
|
||||
|
||||
|
@ -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 <iostream>
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
|
||||
/******
|
||||
* #define ID_DEBUG 1
|
||||
@ -506,21 +508,24 @@ void IdDialog::updateCircles()
|
||||
std::cerr << "Retrieving post data for post " << mThreadId << std::endl;
|
||||
#endif
|
||||
|
||||
std::list<RsGroupMetaData> 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<std::list<RsGroupMetaData>>();
|
||||
|
||||
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<RsGxsGroupId,RsGxsIdGroup> ids_set;
|
||||
|
||||
auto ids_set = std::make_unique<std::map<RsGxsGroupId,RsGxsIdGroup>>();
|
||||
for(auto it(groups.begin()); it!=groups.end(); ++it)
|
||||
ids_set[(*it).mMeta.mGroupId] = *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 );
|
||||
|
||||
});
|
||||
|
@ -210,8 +210,8 @@ void IdEditDialog::setupExistingId(const RsGxsGroupId& keyId)
|
||||
RsThread::async([this,keyId]()
|
||||
{
|
||||
std::vector<RsGxsIdGroup> datavector;
|
||||
|
||||
bool res = rsIdentity->getIdentitiesInfo(std::set<RsGxsId>({(RsGxsId)keyId}),datavector);
|
||||
bool res = rsIdentity->getIdentitiesInfo(
|
||||
std::set<RsGxsId>({(RsGxsId)keyId}), datavector );
|
||||
|
||||
RsQThreadUtils::postToObject( [this,keyId,res,datavector]()
|
||||
{
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include <retroshare/rsstatus.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
|
||||
#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<RsGxsGroupId> ids;
|
||||
|
||||
for(auto& meta:ids_meta)
|
||||
ids.push_back(meta.mGroupId) ;
|
||||
auto ids = std::make_unique<std::vector<RsGxsGroupId>>();
|
||||
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!
|
||||
|
||||
// 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 );
|
||||
});
|
||||
}
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <time.h>
|
||||
#include <memory>
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QFontMetrics>
|
||||
@ -463,24 +464,25 @@ void GxsTransportStatistics::loadGroups()
|
||||
#ifdef DEBUG_FORUMS
|
||||
std::cerr << "Retrieving post data for post " << mThreadId << std::endl;
|
||||
#endif
|
||||
std::map<RsGxsGroupId,RsGxsTransGroupStatistics> stats;
|
||||
auto stats = std::make_unique<
|
||||
std::map<RsGxsGroupId,RsGxsTransGroupStatistics> >();
|
||||
|
||||
if(!rsGxsTrans->getGroupStatistics(stats))
|
||||
if(!rsGxsTrans->getGroupStatistics(*stats))
|
||||
{
|
||||
RsErr() << "Cannot retrieve group statistics in GxsTransportStatistics" << std::endl;
|
||||
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;
|
||||
|
||||
// TODO: consider making mGroupStats an unique_ptr to avoid copying
|
||||
mGroupStats = *stats;
|
||||
updateContent();
|
||||
|
||||
mStateHelper->setLoading(GXSTRANS_GROUP_META, false);
|
||||
|
||||
}, this );
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*******************************************************************************
|
||||
* util/qthreadutils.h *
|
||||
* *
|
||||
* Copyright (C) 2018 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||
* Copyright (C) 2018-2020 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||
* *
|
||||
* 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 <QtGlobal>
|
||||
#include <QtCore>
|
||||
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
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();
|
||||
|
Loading…
Reference in New Issue
Block a user