From 809da97ad329760b83cb9cc0158bf40733c58495 Mon Sep 17 00:00:00 2001 From: stephena Date: Sun, 15 Apr 2012 21:13:01 +0000 Subject: [PATCH] Potential performance improvement for Arrays. A reserve() method is now available, which helps with constant resizes of arrays with a large number of push_backs. For now, only the ROM launcher and debugger disassembly really needs it. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@2442 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- src/common/Array.hxx | 7 +++++++ src/debugger/CartDebug.cxx | 1 + src/gui/LauncherDialog.cxx | 1 + 3 files changed, 9 insertions(+) diff --git a/src/common/Array.hxx b/src/common/Array.hxx index a33834ad5..691424432 100644 --- a/src/common/Array.hxx +++ b/src/common/Array.hxx @@ -58,6 +58,13 @@ class Array delete [] _data; } + void reserve(int capacity) + { + if(capacity <= _capacity) + return; + ensureCapacity(capacity - 128); + } + void push_back(const T& element) { ensureCapacity(_size + 1); diff --git a/src/debugger/CartDebug.cxx b/src/debugger/CartDebug.cxx index fcb223096..763b9d8c5 100644 --- a/src/debugger/CartDebug.cxx +++ b/src/debugger/CartDebug.cxx @@ -278,6 +278,7 @@ bool CartDebug::fillDisassemblyList(BankInfo& info, bool resolvedata, uInt16 sea bool found = false; myDisassembly.list.clear(); + myDisassembly.list.reserve(2048); myDisassembly.fieldwidth = 10 + myLabelLength; DiStella distella(*this, myDisassembly.list, info, myDisLabels, myDisDirectives, resolvedata); diff --git a/src/gui/LauncherDialog.cxx b/src/gui/LauncherDialog.cxx index f217083dc..38bb3bdd2 100644 --- a/src/gui/LauncherDialog.cxx +++ b/src/gui/LauncherDialog.cxx @@ -345,6 +345,7 @@ void LauncherDialog::loadDirListing() return; FSList files; + files.reserve(1024); myCurrentNode.getChildren(files, FilesystemNode::kListAll); // Add '[..]' to indicate previous folder