summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-02-03 17:12:19 +0000
committerrubidium <rubidium@openttd.org>2010-02-03 17:12:19 +0000
commit589aee0cee8fd72ff07fd2dc6043443e07097212 (patch)
treee68d327d0059b1c0c6636ef3bc56dfc9a263d601 /src/network
parentf1458df1caed833434303de9ae59f864404e4d07 (diff)
downloadopenttd-589aee0cee8fd72ff07fd2dc6043443e07097212.tar.xz
(svn r18991) -Codechange: simplify memory management of DownloadSelectedContent
Diffstat (limited to 'src/network')
-rw-r--r--src/network/network_content.cpp17
-rw-r--r--src/network/network_content.h3
2 files changed, 11 insertions, 9 deletions
diff --git a/src/network/network_content.cpp b/src/network/network_content.cpp
index 2346ec3f2..64acd86e0 100644
--- a/src/network/network_content.cpp
+++ b/src/network/network_content.cpp
@@ -253,21 +253,24 @@ void ClientNetworkContentSocketHandler::RequestContentList(ContentVector *cv, bo
void ClientNetworkContentSocketHandler::DownloadSelectedContent(uint &files, uint &bytes)
{
- files = 0;
bytes = 0;
- /** Make the list of items to download */
- ContentID *ids = MallocT<ContentID>(infos.Length());
- for (ContentIterator iter = infos.Begin(); iter != infos.End(); iter++) {
+ ContentIDList content;
+ for (ContentIterator iter = this->infos.Begin(); iter != this->infos.End(); iter++) {
const ContentInfo *ci = *iter;
if (!ci->IsSelected() || ci->state == ContentInfo::ALREADY_HERE) continue;
- ids[files++] = ci->id;
+ *content.Append() = ci->id;
bytes += ci->filesize;
}
+ files = content.Length();
+
+ /* If there's nothing to download, do nothing. */
+ if (files == 0) return;
+
uint count = files;
- ContentID *content_ids = ids;
+ ContentID *content_ids = content.Begin();
this->Connect();
while (count > 0) {
@@ -288,8 +291,6 @@ void ClientNetworkContentSocketHandler::DownloadSelectedContent(uint &files, uin
count -= p_count;
content_ids += p_count;
}
-
- free(ids);
}
/**
diff --git a/src/network/network_content.h b/src/network/network_content.h
index ad9ab3783..ea2df4e39 100644
--- a/src/network/network_content.h
+++ b/src/network/network_content.h
@@ -65,8 +65,9 @@ struct ContentCallback {
*/
class ClientNetworkContentSocketHandler : public NetworkContentSocketHandler, ContentCallback {
protected:
+ typedef SmallVector<ContentID, 4> ContentIDList;
SmallVector<ContentCallback *, 2> callbacks; ///< Callbacks to notify "the world"
- SmallVector<ContentID, 4> requested; ///< ContentIDs we already requested (so we don't do it again)
+ ContentIDList requested; ///< ContentIDs we already requested (so we don't do it again)
ContentVector infos; ///< All content info we received
FILE *curFile; ///< Currently downloaded file