From 4e71b955f601394d4b7e687a4c97baa570fc23c4 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 5 Sep 2019 19:54:14 -0400 Subject: [PATCH] General: Replace loop with resize where applicable Instead of default constructing in a loop for std::vector, we can just use resize or its size constructor to do the same thing. --- specter/lib/Table.cpp | 8 ++------ specter/lib/Toolbar.cpp | 4 +--- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/specter/lib/Table.cpp b/specter/lib/Table.cpp index a43a2aa1b..b97e9ca88 100644 --- a/specter/lib/Table.cpp +++ b/specter/lib/Table.cpp @@ -525,9 +525,7 @@ bool Table::CellView::reset(size_t c, size_t r) { std::vector& Table::ensureCellPools(size_t rows, size_t cols, ViewResources& res) { if (m_cellPools.size() < cols) { - m_cellPools.reserve(cols); - for (size_t i = m_cellPools.size(); i < cols; ++i) - m_cellPools.emplace_back(); + m_cellPools.resize(cols); m_ensuredRows = 0; } if (m_ensuredRows < rows) { @@ -569,9 +567,7 @@ void Table::_updateData() { if (newViewChildren) { m_headerViews.clear(); m_cellPools.clear(); - m_headerViews.reserve(m_columns); - for (size_t c = 0; c < m_columns; ++c) - m_headerViews.emplace_back(); + m_headerViews.resize(m_columns); m_ensuredRows = 0; } ensureCellPools(m_rows, m_columns, res); diff --git a/specter/lib/Toolbar.cpp b/specter/lib/Toolbar.cpp index c585c3b57..9300ab6fd 100644 --- a/specter/lib/Toolbar.cpp +++ b/specter/lib/Toolbar.cpp @@ -20,11 +20,9 @@ void Toolbar::Resources::init(boo::IGraphicsDataFactory::Context& ctx, const ITh Toolbar::Toolbar(ViewResources& res, View& parentView, Position tbPos, unsigned units) : View(res, parentView) , m_units(units) +, m_children(units) , m_nomGauge(res.pixelFactor() * SPECTER_TOOLBAR_GAUGE * units) , m_padding(res.pixelFactor() * TOOLBAR_PADDING) { - m_children.reserve(units); - for (unsigned u = 0; u < units; ++u) - m_children.emplace_back(); commitResources(res, [&](boo::IGraphicsDataFactory::Context& ctx) -> bool { buildResources(ctx, res); m_tbBlockBuf = res.m_viewRes.m_bufPool.allocateBlock(res.m_factory);