From ccf9128cdf80b6259be8a422269d56196461b7c5 Mon Sep 17 00:00:00 2001 From: stephena Date: Sun, 15 Apr 2012 21:39:15 +0000 Subject: [PATCH] A few more places where it makes sense to pre-allocate space for Arrays. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@2443 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- src/common/Array.hxx | 3 ++- src/emucore/FSNode.cxx | 2 +- src/gui/BrowserDialog.cxx | 1 + src/gui/LauncherDialog.cxx | 2 +- src/gui/RomAuditDialog.cxx | 1 + 5 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/common/Array.hxx b/src/common/Array.hxx index 691424432..6e55d5bd7 100644 --- a/src/common/Array.hxx +++ b/src/common/Array.hxx @@ -131,7 +131,8 @@ class Array return *this; } - unsigned int size() const { return _size; } + unsigned int size() const { return _size; } + unsigned int capacity() const { return _capacity; } void clear() { diff --git a/src/emucore/FSNode.cxx b/src/emucore/FSNode.cxx index 3ce917cc7..b88b5d088 100644 --- a/src/emucore/FSNode.cxx +++ b/src/emucore/FSNode.cxx @@ -72,11 +72,11 @@ bool FilesystemNode::getChildren(FSList& fslist, ListMode mode, bool hidden) con return false; AbstractFSList tmp; + tmp.reserve(fslist.capacity()); if (!_realNode->getChildren(tmp, mode, hidden)) return false; - fslist.clear(); for (AbstractFSList::iterator i = tmp.begin(); i != tmp.end(); ++i) { fslist.push_back(FilesystemNode(*i)); diff --git a/src/gui/BrowserDialog.cxx b/src/gui/BrowserDialog.cxx index 63bed1ece..09099303b 100644 --- a/src/gui/BrowserDialog.cxx +++ b/src/gui/BrowserDialog.cxx @@ -168,6 +168,7 @@ void BrowserDialog::updateListing() // Read in the data from the file system FSList content; + content.reserve(2048); _node.getChildren(content, _mode); // Add '[..]' to indicate previous folder diff --git a/src/gui/LauncherDialog.cxx b/src/gui/LauncherDialog.cxx index 38bb3bdd2..2de240e00 100644 --- a/src/gui/LauncherDialog.cxx +++ b/src/gui/LauncherDialog.cxx @@ -345,7 +345,7 @@ void LauncherDialog::loadDirListing() return; FSList files; - files.reserve(1024); + files.reserve(2048); myCurrentNode.getChildren(files, FilesystemNode::kListAll); // Add '[..]' to indicate previous folder diff --git a/src/gui/RomAuditDialog.cxx b/src/gui/RomAuditDialog.cxx index 4c140d99b..c4e2f46d5 100644 --- a/src/gui/RomAuditDialog.cxx +++ b/src/gui/RomAuditDialog.cxx @@ -127,6 +127,7 @@ void RomAuditDialog::auditRoms() FilesystemNode node(auditPath); FSList files; + files.reserve(2048); node.getChildren(files, FilesystemNode::kListFilesOnly); // Create a progress dialog box to show the progress of processing