Commit 17ed6bf837112534fa2295761688b42be63485c7

Authored by Josh Klontz
1 parent cd8172da

removed copy construction in hot code section

openbr/plugins/classification/boostedforest.cpp
@@ -149,10 +149,8 @@ private: @@ -149,10 +149,8 @@ private:
149 } 149 }
150 } 150 }
151 151
152 - float classify(const Template &src, bool process, float *confidence) const 152 + float classifyPreprocessed(const Template &t, float *confidence) const
153 { 153 {
154 - Template t = process ? preprocess(src) : src;  
155 -  
156 float sum = 0; 154 float sum = 0;
157 for (int i = 0; i < classifiers.size(); i++) { 155 for (int i = 0; i < classifiers.size(); i++) {
158 Node *node = classifiers[i]; 156 Node *node = classifiers[i];
@@ -175,6 +173,12 @@ private: @@ -175,6 +173,12 @@ private:
175 return sum < threshold - THRESHOLD_EPS ? 0.0f : 1.0f; 173 return sum < threshold - THRESHOLD_EPS ? 0.0f : 1.0f;
176 } 174 }
177 175
  176 + float classify(const Template &src, bool process, float *confidence) const
  177 + {
  178 + // This code is written in a way to avoid an unnecessary copy construction and destruction of `src` when `process` is false.
  179 + return process ? classifyPreprocessed(preprocess(src), confidence) : classifyPreprocessed(src, confidence);
  180 + }
  181 +
178 int numFeatures() const 182 int numFeatures() const
179 { 183 {
180 return representation->numFeatures(); 184 return representation->numFeatures();