From 206285a27892d1568bcd7ac03ba61b6bfd282ce5 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Sun, 2 Jun 2024 11:02:12 -0700 Subject: [PATCH] Use reserve() to pre-allocate for push_back() iteration --- src/Forest.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Forest.h b/src/Forest.h index e9279154..265d8c78 100644 --- a/src/Forest.h +++ b/src/Forest.h @@ -147,6 +147,7 @@ class Forest { std::vector> getNumSamplesNodes() { std::vector> result; + result.reserve(trees.size()); for (auto& tree : trees) { result.push_back(tree->getNumSamplesNodes()); } @@ -154,6 +155,7 @@ class Forest { } std::vector> getNodePredictions() { std::vector> result; + result.reserve(trees.size()); for (auto& tree : trees) { result.push_back(tree->getNodePredictions()); } @@ -161,6 +163,7 @@ class Forest { } std::vector> getSplitStats() { std::vector> result; + result.reserve(trees.size()); for (auto& tree : trees) { result.push_back(tree->getSplitStats()); }