diff options
author | Tetsuo Kiso <tetsuo-s@is.naist.jp> | 2012-04-12 04:40:52 +0400 |
---|---|---|
committer | Tetsuo Kiso <tetsuo-s@is.naist.jp> | 2012-04-12 04:40:52 +0400 |
commit | 408dd72f9d137475aa14aca97290e05f6e5133c0 (patch) | |
tree | 89f1c492b63980f1b438a03b2fb1904679691c99 /mert/Point.cpp | |
parent | 0e9b5fd9d0b7458a938a02fd73f23b07b462a3ba (diff) |
Pass by reference instead of returning objects.
In the previous implementation, copy-constructor got called, which
was not necessary. This commit prevents it, making code more efficient.
Diffstat (limited to 'mert/Point.cpp')
-rw-r--r-- | mert/Point.cpp | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/mert/Point.cpp b/mert/Point.cpp index 085c71339..299e2b4d0 100644 --- a/mert/Point.cpp +++ b/mert/Point.cpp @@ -109,7 +109,8 @@ const Point Point::operator*(float l) const ostream& operator<<(ostream& o, const Point& P) { - vector<parameter_t> w = P.GetAllWeights(); + vector<parameter_t> w; + P.GetAllWeights(w); for (unsigned int i = 0; i < Point::m_pdim; i++) { o << w[i] << " "; } @@ -141,19 +142,17 @@ void Point::NormalizeL1() } -vector<parameter_t> Point::GetAllWeights()const +void Point::GetAllWeights(vector<parameter_t>& w) const { - vector<parameter_t> w; if (OptimizeAll()) { w = *this; } else { w.resize(m_pdim); for (unsigned int i = 0; i < size(); i++) w[m_opt_indices[i]] = operator[](i); - for (map<unsigned, float>::iterator it = m_fixed_weights.begin(); + for (map<unsigned,float>::const_iterator it = m_fixed_weights.begin(); it != m_fixed_weights.end(); ++it) { w[it->first]=it->second; } } - return w; } |