From 17ed6bf837112534fa2295761688b42be63485c7 Mon Sep 17 00:00:00 2001 From: Josh Klontz Date: Thu, 29 Oct 2015 14:46:32 -0400 Subject: [PATCH] removed copy construction in hot code section --- openbr/plugins/classification/boostedforest.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/openbr/plugins/classification/boostedforest.cpp b/openbr/plugins/classification/boostedforest.cpp index 3cf941e..4d97f35 100644 --- a/openbr/plugins/classification/boostedforest.cpp +++ b/openbr/plugins/classification/boostedforest.cpp @@ -149,10 +149,8 @@ private: } } - float classify(const Template &src, bool process, float *confidence) const + float classifyPreprocessed(const Template &t, float *confidence) const { - Template t = process ? preprocess(src) : src; - float sum = 0; for (int i = 0; i < classifiers.size(); i++) { Node *node = classifiers[i]; @@ -175,6 +173,12 @@ private: return sum < threshold - THRESHOLD_EPS ? 0.0f : 1.0f; } + float classify(const Template &src, bool process, float *confidence) const + { + // This code is written in a way to avoid an unnecessary copy construction and destruction of `src` when `process` is false. + return process ? classifyPreprocessed(preprocess(src), confidence) : classifyPreprocessed(src, confidence); + } + int numFeatures() const { return representation->numFeatures(); -- libgit2 0.21.4