Optimizations in RsGenExchange, p3GxsForums and p3GxsChannels.

- Removed not used variables
- avoid copy constructors
- Use swap instead of operator= to move elements of std containers
This commit is contained in:
thunder2 2015-09-08 16:34:22 +02:00
parent 490b88c16a
commit ebd5da5e83
4 changed files with 13 additions and 26 deletions

View File

@ -1135,7 +1135,6 @@ bool RsGenExchange::getGroupMeta(const uint32_t &token, std::list<RsGroupMetaDat
return ok; return ok;
} }
bool RsGenExchange::getMsgMeta(const uint32_t &token, bool RsGenExchange::getMsgMeta(const uint32_t &token,
GxsMsgMetaMap &msgInfo) GxsMsgMetaMap &msgInfo)
{ {
@ -1152,7 +1151,6 @@ bool RsGenExchange::getMsgMeta(const uint32_t &token,
{ {
std::vector<RsGxsMsgMetaData*>& metaV = mit->second; std::vector<RsGxsMsgMetaData*>& metaV = mit->second;
msgInfo[mit->first] = std::vector<RsMsgMetaData>();
std::vector<RsMsgMetaData>& msgInfoV = msgInfo[mit->first]; std::vector<RsMsgMetaData>& msgInfoV = msgInfo[mit->first];
std::vector<RsGxsMsgMetaData*>::iterator vit = metaV.begin(); std::vector<RsGxsMsgMetaData*>::iterator vit = metaV.begin();
@ -1181,7 +1179,6 @@ bool RsGenExchange::getMsgRelatedMeta(const uint32_t &token, GxsMsgRelatedMetaMa
{ {
std::vector<RsGxsMsgMetaData*>& metaV = mit->second; std::vector<RsGxsMsgMetaData*>& metaV = mit->second;
msgMeta[mit->first] = std::vector<RsMsgMetaData>();
std::vector<RsMsgMetaData>& msgInfoV = msgMeta[mit->first]; std::vector<RsMsgMetaData>& msgInfoV = msgMeta[mit->first];
std::vector<RsGxsMsgMetaData*>::iterator vit = metaV.begin(); std::vector<RsGxsMsgMetaData*>::iterator vit = metaV.begin();
@ -1265,14 +1262,14 @@ bool RsGenExchange::getMsgData(const uint32_t &token, GxsMsgDataMap &msgItems)
RS_STACK_MUTEX(mGenMtx) ; RS_STACK_MUTEX(mGenMtx) ;
NxsMsgDataResult msgResult; NxsMsgDataResult msgResult;
bool ok = mDataAccess->getMsgData(token, msgResult); bool ok = mDataAccess->getMsgData(token, msgResult);
NxsMsgDataResult::iterator mit = msgResult.begin();
if(ok) if(ok)
{ {
NxsMsgDataResult::iterator mit = msgResult.begin();
for(; mit != msgResult.end(); ++mit) for(; mit != msgResult.end(); ++mit)
{ {
std::vector<RsGxsMsgItem*> gxsMsgItems;
const RsGxsGroupId& grpId = mit->first; const RsGxsGroupId& grpId = mit->first;
std::vector<RsGxsMsgItem*>& gxsMsgItems = msgItems[grpId];
std::vector<RsNxsMsg*>& nxsMsgsV = mit->second; std::vector<RsNxsMsg*>& nxsMsgsV = mit->second;
std::vector<RsNxsMsg*>::iterator vit = nxsMsgsV.begin(); std::vector<RsNxsMsg*>::iterator vit = nxsMsgsV.begin();
for(; vit != nxsMsgsV.end(); ++vit) for(; vit != nxsMsgsV.end(); ++vit)
@ -1305,7 +1302,6 @@ bool RsGenExchange::getMsgData(const uint32_t &token, GxsMsgDataMap &msgItems)
} }
delete msg; delete msg;
} }
msgItems[grpId] = gxsMsgItems;
} }
} }
return ok; return ok;
@ -1317,17 +1313,15 @@ bool RsGenExchange::getMsgRelatedData(const uint32_t &token, GxsMsgRelatedDataMa
NxsMsgRelatedDataResult msgResult; NxsMsgRelatedDataResult msgResult;
bool ok = mDataAccess->getMsgRelatedData(token, msgResult); bool ok = mDataAccess->getMsgRelatedData(token, msgResult);
if(ok) if(ok)
{ {
NxsMsgRelatedDataResult::iterator mit = msgResult.begin(); NxsMsgRelatedDataResult::iterator mit = msgResult.begin();
for(; mit != msgResult.end(); ++mit) for(; mit != msgResult.end(); ++mit)
{ {
std::vector<RsGxsMsgItem*> gxsMsgItems;
const RsGxsGrpMsgIdPair& msgId = mit->first; const RsGxsGrpMsgIdPair& msgId = mit->first;
std::vector<RsGxsMsgItem*> &gxsMsgItems = msgItems[msgId];
std::vector<RsNxsMsg*>& nxsMsgsV = mit->second; std::vector<RsNxsMsg*>& nxsMsgsV = mit->second;
std::vector<RsNxsMsg*>::iterator vit std::vector<RsNxsMsg*>::iterator vit = nxsMsgsV.begin();
= nxsMsgsV.begin();
for(; vit != nxsMsgsV.end(); ++vit) for(; vit != nxsMsgsV.end(); ++vit)
{ {
RsNxsMsg*& msg = *vit; RsNxsMsg*& msg = *vit;
@ -1360,15 +1354,11 @@ bool RsGenExchange::getMsgRelatedData(const uint32_t &token, GxsMsgRelatedDataMa
delete msg; delete msg;
} }
msgItems[msgId] = gxsMsgItems;
} }
} }
return ok; return ok;
} }
RsTokenService* RsGenExchange::getTokenService() RsTokenService* RsGenExchange::getTokenService()
{ {
return mDataAccess; return mDataAccess;

View File

@ -448,7 +448,7 @@ bool RsGxsDataAccess::getGroupData(const uint32_t& token, std::list<RsNxsGrp*>&
if(gmreq) if(gmreq)
{ {
grpData = gmreq->mGroupData; grpData.swap(gmreq->mGroupData);
gmreq->mGroupData.clear(); gmreq->mGroupData.clear();
locked_updateRequestStatus(token, GXS_REQUEST_V2_STATUS_DONE); locked_updateRequestStatus(token, GXS_REQUEST_V2_STATUS_DONE);
}else{ }else{
@ -480,7 +480,7 @@ bool RsGxsDataAccess::getMsgData(const uint32_t& token, NxsMsgDataResult& msgDat
if(mdreq) if(mdreq)
{ {
msgData = mdreq->mMsgData; msgData.swap(mdreq->mMsgData);
mdreq->mMsgData.clear(); mdreq->mMsgData.clear();
locked_updateRequestStatus(token, GXS_REQUEST_V2_STATUS_DONE); locked_updateRequestStatus(token, GXS_REQUEST_V2_STATUS_DONE);
} }
@ -517,7 +517,7 @@ bool RsGxsDataAccess::getMsgRelatedData(const uint32_t &token, NxsMsgRelatedData
if(mrireq) if(mrireq)
{ {
msgData = mrireq->mMsgDataResult; msgData.swap(mrireq->mMsgDataResult);
mrireq->mMsgDataResult.clear(); mrireq->mMsgDataResult.clear();
locked_updateRequestStatus(token, GXS_REQUEST_V2_STATUS_DONE); locked_updateRequestStatus(token, GXS_REQUEST_V2_STATUS_DONE);
} }
@ -551,7 +551,7 @@ bool RsGxsDataAccess::getMsgSummary(const uint32_t& token, GxsMsgMetaResult& msg
if(mmreq) if(mmreq)
{ {
msgInfo = mmreq->mMsgMetaData; msgInfo.swap(mmreq->mMsgMetaData);
mmreq->mMsgMetaData.clear(); mmreq->mMsgMetaData.clear();
locked_updateRequestStatus(token, GXS_REQUEST_V2_STATUS_DONE); locked_updateRequestStatus(token, GXS_REQUEST_V2_STATUS_DONE);
@ -591,7 +591,7 @@ bool RsGxsDataAccess::getMsgRelatedSummary(const uint32_t &token, MsgRelatedMeta
if(mrireq) if(mrireq)
{ {
msgMeta = mrireq->mMsgMetaResult; msgMeta.swap(mrireq->mMsgMetaResult);
mrireq->mMsgMetaResult.clear(); mrireq->mMsgMetaResult.clear();
locked_updateRequestStatus(token, GXS_REQUEST_V2_STATUS_DONE); locked_updateRequestStatus(token, GXS_REQUEST_V2_STATUS_DONE);
} }
@ -630,7 +630,7 @@ bool RsGxsDataAccess::getMsgRelatedList(const uint32_t &token, MsgRelatedIdResul
if(mrireq) if(mrireq)
{ {
msgIds = mrireq->mMsgIdResult; msgIds.swap(mrireq->mMsgIdResult);
mrireq->mMsgIdResult.clear(); mrireq->mMsgIdResult.clear();
locked_updateRequestStatus(token, GXS_REQUEST_V2_STATUS_DONE); locked_updateRequestStatus(token, GXS_REQUEST_V2_STATUS_DONE);
} }
@ -664,7 +664,7 @@ bool RsGxsDataAccess::getMsgList(const uint32_t& token, GxsMsgIdResult& msgIds)
if(mireq) if(mireq)
{ {
msgIds = mireq->mMsgIdResult; msgIds.swap(mireq->mMsgIdResult);
mireq->mMsgIdResult.clear(); mireq->mMsgIdResult.clear();
locked_updateRequestStatus(token, GXS_REQUEST_V2_STATUS_DONE); locked_updateRequestStatus(token, GXS_REQUEST_V2_STATUS_DONE);
} }
@ -697,7 +697,7 @@ bool RsGxsDataAccess::getGroupList(const uint32_t& token, std::list<RsGxsGroupId
if(gireq) if(gireq)
{ {
groupIds = gireq->mGroupIdResult; groupIds.swap(gireq->mGroupIdResult);
gireq->mGroupIdResult.clear(); gireq->mGroupIdResult.clear();
locked_updateRequestStatus(token, GXS_REQUEST_V2_STATUS_DONE); locked_updateRequestStatus(token, GXS_REQUEST_V2_STATUS_DONE);

View File

@ -337,7 +337,6 @@ bool p3GxsChannels::getPostData(const uint32_t &token, std::vector<RsGxsChannelP
for(; mit != msgData.end(); ++mit) for(; mit != msgData.end(); ++mit)
{ {
RsGxsGroupId grpId = mit->first;
std::vector<RsGxsMsgItem*>& msgItems = mit->second; std::vector<RsGxsMsgItem*>& msgItems = mit->second;
std::vector<RsGxsMsgItem*>::iterator vit = msgItems.begin(); std::vector<RsGxsMsgItem*>::iterator vit = msgItems.begin();

View File

@ -199,8 +199,7 @@ bool p3GxsForums::getGroupData(const uint32_t &token, std::vector<RsGxsForumGrou
if (item) if (item)
{ {
RsGxsForumGroup grp = item->mGroup; RsGxsForumGroup grp = item->mGroup;
item->mGroup.mMeta = item->meta; grp.mMeta = item->meta;
grp.mMeta = item->mGroup.mMeta;
delete item; delete item;
groups.push_back(grp); groups.push_back(grp);
} }
@ -230,7 +229,6 @@ bool p3GxsForums::getMsgData(const uint32_t &token, std::vector<RsGxsForumMsg> &
for(; mit != msgData.end(); ++mit) for(; mit != msgData.end(); ++mit)
{ {
RsGxsGroupId grpId = mit->first;
std::vector<RsGxsMsgItem*>& msgItems = mit->second; std::vector<RsGxsMsgItem*>& msgItems = mit->second;
std::vector<RsGxsMsgItem*>::iterator vit = msgItems.begin(); std::vector<RsGxsMsgItem*>::iterator vit = msgItems.begin();