commit 35611c985c5d5bc253a4962f59e2f4919fe77ff2
parent 02f411a8fdb2fe87a7b45defec2dd3fac6186917
Author: cfillion <cfillion@users.noreply.github.com>
Date: Sat, 26 Aug 2017 22:45:01 -0400
listview: avoid copying previous rows and cells on insertion
Diffstat:
6 files changed, 28 insertions(+), 13 deletions(-)
diff --git a/src/about.cpp b/src/about.cpp
@@ -298,6 +298,7 @@ void AboutIndexDelegate::init(About *dialog)
dialog->menu()->addColumn({AUTO_STR("Category"), 142});
+ dialog->menu()->reserveRows(m_index->categories().size() + 1);
dialog->menu()->addRow({AUTO_STR("<All Packages>")});
for(const Category *cat : m_index->categories())
@@ -369,6 +370,7 @@ void AboutIndexDelegate::updateList(const int index)
else
packages = &m_index->category(catIndex)->packages();
+ m_dialog->list()->reserveRows(packages->size());
for(const Package *pkg : *packages) {
const Version *lastVer = pkg->lastVersion();
const auto_string &name = make_autostring(pkg->displayName());
@@ -534,6 +536,7 @@ void AboutPackageDelegate::init(About *dialog)
dialog->list()->addColumn({AUTO_STR("File"), 474});
dialog->list()->addColumn({AUTO_STR("Action List"), 84});
+ dialog->menu()->reserveRows(m_package->versions().size());
for(const Version *ver : m_package->versions()) {
const auto index = dialog->menu()->addRow({
{make_autostring(ver->name().toString()), (void *)&ver->name()}
@@ -566,6 +569,7 @@ void AboutPackageDelegate::updateList(const int index)
SetWindowText(m_dialog->getControl(IDC_CHANGELOG),
make_autostring(stream.str()).c_str());
+ m_dialog->list()->reserveRows(ver->sources().size());
for(const Source *src : ver->sources()) {
int sections = src->sections();
string actionList;
diff --git a/src/browser.cpp b/src/browser.cpp
@@ -523,6 +523,7 @@ void Browser::fillList()
oldSelection[i] = (Entry *)m_list->row(selectedIndexes[i]).userData;
m_list->clear();
+ m_list->reserveRows(m_entries.size());
for(const Entry &entry : m_entries) {
if(!match(entry))
diff --git a/src/browser_entry.cpp b/src/browser_entry.cpp
@@ -156,16 +156,18 @@ ListView::Row Browser::Entry::makeRow() const
const Time *time = lastUpdate();
ListView::Row row;
+ row.reserve(8);
row.userData = (void *)this;
- row.push_back(make_autostring(displayState()));
- row.push_back(make_autostring(displayName()));
- row.push_back(make_autostring(categoryName()));
- row.push_back({make_autostring(displayVersion()), (void *)sortVersion()});
- row.push_back(make_autostring(displayAuthor()));
- row.push_back(make_autostring(displayType()));
- row.push_back(make_autostring(indexName()));
- row.push_back({time ? make_autostring(time->toString()) : auto_string(),
- (void *)time});
+ row.emplace_back(make_autostring(displayState()));
+ row.emplace_back(make_autostring(displayName()));
+ row.emplace_back(make_autostring(categoryName()));
+ row.emplace_back(ListView::Cell{
+ make_autostring(displayVersion()), (void *)sortVersion()});
+ row.emplace_back(make_autostring(displayAuthor()));
+ row.emplace_back(make_autostring(displayType()));
+ row.emplace_back(make_autostring(indexName()));
+ row.emplace_back(ListView::Cell{time ?
+ make_autostring(time->toString()) : auto_string(), (void *)time});
return row;
}
diff --git a/src/listview.hpp b/src/listview.hpp
@@ -79,6 +79,7 @@ public:
ListView(HWND handle, const Columns & = {});
int addRow(const Row &row);
+ void reserveRows(size_t count) { m_rows.reserve(count); }
const Row &row(int index) const { return m_rows[index]; }
void setCell(int row, int index, const Cell &);
void removeRow(int index);
diff --git a/src/manager.cpp b/src/manager.cpp
@@ -320,15 +320,20 @@ void Manager::refresh()
for(size_t i = 0; i < selection.size(); i++)
selected[i] = from_autostring(m_list->row(selection[i])[0].value); // TODO: use data ptr to Remote
+ const auto &remotes = g_reapack->config()->remotes;
+
m_list->clear();
+ m_list->reserveRows(remotes.size());
- for(const Remote &remote : g_reapack->config()->remotes) {
+ for(const Remote &remote : remotes) {
if(m_uninstall.count(remote))
continue;
- ListView::Row row(3, ListView::Cell{});
- row[0] = make_autostring(remote.name());
- row[1] = make_autostring(remote.url());
+ ListView::Row row;
+ row.reserve(3);
+ row.emplace_back(make_autostring(remote.name()));
+ row.emplace_back(make_autostring(remote.url()));
+ row.emplace_back(ListView::Cell{});
const int index = m_list->addRow(row);
updateEnabledCell(index, remote);
diff --git a/src/obsquery.cpp b/src/obsquery.cpp
@@ -52,6 +52,8 @@ void ObsoleteQuery::onInit()
return true;
});
+ m_list->reserveRows(m_entries->size());
+
for(const Registry::Entry &entry : *m_entries) {
ostringstream stream;
stream << entry.remote << '/' << entry.category << '/'