From 265de59917bdf94709b40ad8aef5dd9ce5574242 Mon Sep 17 00:00:00 2001 From: David Allemang Date: Wed, 14 Oct 2020 17:11:39 -0400 Subject: [PATCH] Only reserve output size in path::walk --- include/tc/core.hpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/include/tc/core.hpp b/include/tc/core.hpp index 8594adc..7f91889 100644 --- a/include/tc/core.hpp +++ b/include/tc/core.hpp @@ -55,14 +55,15 @@ namespace tc { std::vector gens, std::function op ) const { - std::vector res(size()); - res[0] = start; + std::vector res; + res.reserve(size()); + res.push_back(start); - for (int i = 1; i < res.size(); ++i) { + for (int i = 1; i < size(); ++i) { auto &action = path[i]; auto &from = res[action.from_idx]; auto &val = gens[action.gen]; - res[i] = op(from, val); + res.push_back(op(from, val)); } return res; @@ -73,10 +74,11 @@ namespace tc { T start, std::function op ) const { - std::vector res(size()); - res[0] = start; + std::vector res; + res.reserve(size()); + res.push_back(start); - for (int i = 1; i < res.size(); ++i) { + for (int i = 1; i < size(); ++i) { auto &action = path[i]; auto &from = res[action.from_idx]; auto &val = action.gen; @@ -127,7 +129,7 @@ namespace tc { struct SubGroup; struct Group { - const int ngens; + int ngens; std::vector> _mults; std::string name;