diff options
author | Tetsuo Kiso <tetsuo-s@is.naist.jp> | 2012-02-25 21:12:59 +0400 |
---|---|---|
committer | Tetsuo Kiso <tetsuo-s@is.naist.jp> | 2012-02-25 21:12:59 +0400 |
commit | 224c654fa52861f5ae00f6969ca2b27f10488cbe (patch) | |
tree | 0c49573b69d48c1ecbba957080131e12c997cf63 /mert/BleuScorer.cpp | |
parent | 669b9d9c7aab3553df561b4b6e1f1328669d5ef2 (diff) |
Don't repeat calling functions many times.
Consider using constants the result if it is possible.
Diffstat (limited to 'mert/BleuScorer.cpp')
-rw-r--r-- | mert/BleuScorer.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/mert/BleuScorer.cpp b/mert/BleuScorer.cpp index efa189aa1..d6266dd6c 100644 --- a/mert/BleuScorer.cpp +++ b/mert/BleuScorer.cpp @@ -272,12 +272,14 @@ void BleuScorer::CalcClosest(size_t sentence_id, int min_idx = 0; for (size_t i = 0; i < m_ref_lengths[sentence_id].size(); ++i) { const int reflength = m_ref_lengths[sentence_id][i]; + const int length_diff = abs(reflength - static_cast<int>(length)); + // Look for the closest reference - if (abs(reflength - static_cast<int>(length)) < abs(min_diff)) { + if (length_diff < abs(min_diff)) { min_diff = reflength - length; min_idx = i; - // if two references has the same closest length, take the shortest - } else if (abs(reflength - static_cast<int>(length)) == abs(min_diff)) { + // if two references has the same closest length, take the shortest + } else if (length_diff == abs(min_diff)) { if (reflength < static_cast<int>(m_ref_lengths[sentence_id][min_idx])) { min_idx = i; } |