linuxdcpp-team team mailing list archive
-
linuxdcpp-team team
-
Mailing list archive
-
Message #05168
[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2802: Reclaim memory after a file list match
------------------------------------------------------------
revno: 2802
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Sun 2012-01-08 14:03:30 +0100
message:
Reclaim memory after a file list match
modified:
changelog.txt
dcpp/QueueManager.cpp
--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk
Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'changelog.txt'
--- changelog.txt 2012-01-07 18:16:19 +0000
+++ changelog.txt 2012-01-08 13:03:30 +0000
@@ -3,6 +3,7 @@
* Heuristics to send additional levels of info in partial file lists (poy)
* Add a "Download full list" button in the file list toolbar (poy)
* "Get file list" now defaults to partial file lists (poy)
+* Reclaim memory after a file list match
-- 0.790 2011-12-29 --
* Fav users frame becomes users frame and shows all users
=== modified file 'dcpp/QueueManager.cpp'
--- dcpp/QueueManager.cpp 2012-01-06 23:14:39 +0000
+++ dcpp/QueueManager.cpp 2012-01-08 13:03:30 +0000
@@ -736,35 +736,33 @@
}
return qi->getPriority();
}
+
+typedef unordered_map<TTHValue, const DirectoryListing::File*> TTHMap;
+
namespace {
-typedef unordered_map<TTHValue, const DirectoryListing::File*> TTHMap;
-
-// *** WARNING ***
-// Lock(cs) makes sure that there's only one thread accessing this
-static TTHMap tthMap;
-
-void buildMap(const DirectoryListing::Directory* dir) noexcept {
- for(auto j = dir->directories.begin(); j != dir->directories.end(); ++j) {
- if(!(*j)->getAdls())
- buildMap(*j);
- }
-
- for(auto i = dir->files.begin(); i != dir->files.end(); ++i) {
- const DirectoryListing::File* df = *i;
- tthMap.insert(make_pair(df->getTTH(), df));
- }
+void buildMap(const DirectoryListing::Directory* dir, TTHMap& tthMap) noexcept {
+ std::for_each(dir->directories.cbegin(), dir->directories.cend(), [&](DirectoryListing::Directory* d) {
+ if(!d->getAdls())
+ buildMap(d, tthMap);
+ });
+
+ std::for_each(dir->files.cbegin(), dir->files.cend(), [&](DirectoryListing::File* f) {
+ tthMap.insert(make_pair(f->getTTH(), f));
+ });
}
}
int QueueManager::matchListing(const DirectoryListing& dl) noexcept {
int matches = 0;
+
{
Lock l(cs);
- tthMap.clear();
- buildMap(dl.getRoot());
-
- for(auto i = fileQueue.getQueue().begin(); i != fileQueue.getQueue().end(); ++i) {
- QueueItem* qi = i->second;
+
+ TTHMap tthMap;
+ buildMap(dl.getRoot(), tthMap);
+
+ for(auto i = fileQueue.getQueue().cbegin(), iend = fileQueue.getQueue().cend(); i != iend; ++i) {
+ auto qi = i->second;
if(qi->isFinished())
continue;
if(qi->isSet(QueueItem::FLAG_USER_LIST))