diff options
author | Jeroen Vermeulen <jtv@precisiontranslationtools.com> | 2015-04-10 09:25:51 +0300 |
---|---|---|
committer | Jeroen Vermeulen <jtv@precisiontranslationtools.com> | 2015-04-10 09:25:51 +0300 |
commit | b8793fb78871f90b2626b55455ab3a804a49330a (patch) | |
tree | 383ccd0c72a11903cb975eae6a50f53b7d6033e0 /mert/evaluator.cpp | |
parent | 8a3ae2fd5c4fc11fafe2ba64cf29a655688f043a (diff) |
Address two TODO notes in mert/evaluator.cpp.
The notes were about two objects which were created on the free store
using "new", then cleaned up using "delete". May have been a Java
habit; the solution was as simple as creating them on the stack.
Diffstat (limited to 'mert/evaluator.cpp')
-rw-r--r-- | mert/evaluator.cpp | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/mert/evaluator.cpp b/mert/evaluator.cpp index 4e791fc6e..026abf397 100644 --- a/mert/evaluator.cpp +++ b/mert/evaluator.cpp @@ -92,17 +92,15 @@ void EvaluatorUtil::evaluate(const string& candFile, int bootstrap, bool nbest_i if (bootstrap) { vector<float> scores; for (int i = 0; i < bootstrap; ++i) { - // TODO: Use smart pointer for exceptional-safety. - ScoreData* scoredata = new ScoreData(g_scorer); + ScoreData scoredata(g_scorer); for (int j = 0; j < n; ++j) { int randomIndex = random() % n; - scoredata->add(entries[randomIndex], j); + scoredata.add(entries[randomIndex], j); } - g_scorer->setScoreData(scoredata); + g_scorer->setScoreData(&scoredata); candidates_t candidates(n, 0); float score = g_scorer->score(candidates); scores.push_back(score); - delete scoredata; } float avg = average(scores); @@ -122,15 +120,13 @@ void EvaluatorUtil::evaluate(const string& candFile, int bootstrap, bool nbest_i cout.precision(4); cout << avg << "\t[" << lb << "," << rb << "]" << endl; } else { - // TODO: Use smart pointer for exceptional-safety. - ScoreData* scoredata = new ScoreData(g_scorer); + ScoreData scoredata(g_scorer); for (int sid = 0; sid < n; ++sid) { - scoredata->add(entries[sid], sid); + scoredata.add(entries[sid], sid); } - g_scorer->setScoreData(scoredata); + g_scorer->setScoreData(&scoredata); candidates_t candidates(n, 0); float score = g_scorer->score(candidates); - delete scoredata; if (g_has_more_files) cout << candFile << "\t"; if (g_has_more_scorers) cout << g_scorer->getName() << "\t"; |