mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-10-05 15:58:03 +03:00
clean up recycler, use stack instead of dequeue
This commit is contained in:
parent
bd5300eef0
commit
bf8691e94d
@ -28,6 +28,7 @@ ManagerBase::ManagerBase(System &sys, const TranslationTask &task,
|
||||
,m_translationId(translationId)
|
||||
,m_pool(NULL)
|
||||
,m_systemPool(NULL)
|
||||
,m_hypoRecycler(NULL)
|
||||
,m_input(NULL)
|
||||
{
|
||||
}
|
||||
|
@ -34,7 +34,6 @@ Hypothesis *Hypothesis::Create(Manager &mgr)
|
||||
} else {
|
||||
ret = new (pool.Allocate<Hypothesis>()) Hypothesis(pool, mgr.system);
|
||||
//cerr << "Hypothesis=" << sizeof(Hypothesis) << " " << ret << endl;
|
||||
recycler.Keep(ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <deque>
|
||||
#include <stack>
|
||||
#include <vector>
|
||||
|
||||
namespace Moses2
|
||||
@ -17,20 +17,16 @@ template<typename T>
|
||||
class Recycler
|
||||
{
|
||||
public:
|
||||
Recycler() :
|
||||
m_currInd(0) {
|
||||
Recycler() {
|
||||
}
|
||||
|
||||
virtual ~Recycler() {
|
||||
}
|
||||
|
||||
T Get() {
|
||||
if (!m_coll.empty()) {
|
||||
T &obj = m_coll.back();
|
||||
m_coll.pop_back();
|
||||
return obj;
|
||||
} else if (m_currInd) {
|
||||
--m_currInd;
|
||||
T &obj = m_all[m_currInd];
|
||||
T &obj = m_coll.top();
|
||||
m_coll.pop();
|
||||
return obj;
|
||||
} else {
|
||||
return NULL;
|
||||
@ -39,30 +35,16 @@ public:
|
||||
|
||||
void Clear() {
|
||||
m_coll.clear();
|
||||
m_all.clear();
|
||||
m_currInd = 0;
|
||||
}
|
||||
|
||||
// call this for new objects when u 1st create it. It is assumed the object will be used right away
|
||||
void Keep(const T& val) {
|
||||
m_all.push_back(val);
|
||||
}
|
||||
|
||||
// call this for existing object to put back into queue for reuse
|
||||
void Recycle(const T& val) {
|
||||
m_coll.push_back(val);
|
||||
m_coll.push(val);
|
||||
}
|
||||
|
||||
protected:
|
||||
// all objects we're looking after
|
||||
std::vector<T> m_all;
|
||||
|
||||
// pointer to the object that's just been given out.
|
||||
// to give out another obj, must decrement THEN give out
|
||||
size_t m_currInd;
|
||||
|
||||
// objects that have been give back to us
|
||||
std::deque<T> m_coll;
|
||||
std::stack<T> m_coll;
|
||||
};
|
||||
|
||||
} /* namespace Moses2 */
|
||||
|
@ -29,7 +29,6 @@ Hypothesis *Hypothesis::Create(Manager &mgr)
|
||||
} else {
|
||||
ret = new (pool.Allocate<Hypothesis>()) Hypothesis(pool, mgr.system);
|
||||
//cerr << "Hypothesis=" << sizeof(Hypothesis) << " " << ret << endl;
|
||||
recycler.Keep(ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user