Commit 17ed6bf837112534fa2295761688b42be63485c7
1 parent
cd8172da
removed copy construction in hot code section
Showing
1 changed file
with
7 additions
and
3 deletions
openbr/plugins/classification/boostedforest.cpp
| ... | ... | @@ -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 | 154 | float sum = 0; |
| 157 | 155 | for (int i = 0; i < classifiers.size(); i++) { |
| 158 | 156 | Node *node = classifiers[i]; |
| ... | ... | @@ -175,6 +173,12 @@ private: |
| 175 | 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 | 182 | int numFeatures() const |
| 179 | 183 | { |
| 180 | 184 | return representation->numFeatures(); | ... | ... |