diff --git a/contrib/other-builds/moses2/FF/Distortion.cpp b/contrib/other-builds/moses2/FF/Distortion.cpp index d13f01775..ca43fba7d 100644 --- a/contrib/other-builds/moses2/FF/Distortion.cpp +++ b/contrib/other-builds/moses2/FF/Distortion.cpp @@ -56,9 +56,9 @@ Moses::FFState* Distortion::BlankState(const Manager &mgr, const PhraseImpl &inp return new (pool.Allocate()) DistortionState_traditional(); } -Moses::FFState* Distortion::EmptyHypothesisState(const Manager &mgr, const PhraseImpl &input) const +void Distortion::EmptyHypothesisState(Moses::FFState &state, const Manager &mgr, const PhraseImpl &input) const { - MemPool &pool = mgr.GetPool(); + DistortionState_traditional &stateCast = static_cast(state); // fake previous translated phrase start and end size_t start = NOT_FOUND; @@ -70,10 +70,9 @@ Moses::FFState* Distortion::EmptyHypothesisState(const Manager &mgr, const Phras end = input.m_frontSpanCoveredLength -1; } */ - return new (pool.Allocate()) DistortionState_traditional( - Moses::Range(start, end), - NOT_FOUND); + stateCast.range = Moses::Range(start, end); + stateCast.first_gap = NOT_FOUND; } void diff --git a/contrib/other-builds/moses2/FF/Distortion.h b/contrib/other-builds/moses2/FF/Distortion.h index 8b0daed5e..5a1605810 100644 --- a/contrib/other-builds/moses2/FF/Distortion.h +++ b/contrib/other-builds/moses2/FF/Distortion.h @@ -19,7 +19,7 @@ public: virtual ~Distortion(); virtual Moses::FFState* BlankState(const Manager &mgr, const PhraseImpl &input) const; - virtual Moses::FFState* EmptyHypothesisState(const Manager &mgr, const PhraseImpl &input) const; + virtual void EmptyHypothesisState(Moses::FFState &state, const Manager &mgr, const PhraseImpl &input) const; virtual void EvaluateInIsolation(const System &system, diff --git a/contrib/other-builds/moses2/FF/SkeletonStatefulFF.cpp b/contrib/other-builds/moses2/FF/SkeletonStatefulFF.cpp index a6d5b5c78..14d12f4a0 100644 --- a/contrib/other-builds/moses2/FF/SkeletonStatefulFF.cpp +++ b/contrib/other-builds/moses2/FF/SkeletonStatefulFF.cpp @@ -10,23 +10,20 @@ class SkeletonState : public Moses::FFState { - int m_targetLen; public: + int targetLen; + SkeletonState() { // uninitialised } - SkeletonState(int targetLen) - :m_targetLen(targetLen) { - } - virtual size_t hash() const { - return (size_t) m_targetLen; + return (size_t) targetLen; } virtual bool operator==(const Moses::FFState& o) const { const SkeletonState& other = static_cast(o); - return m_targetLen == other.m_targetLen; + return targetLen == other.targetLen; } }; @@ -48,10 +45,10 @@ Moses::FFState* SkeletonStatefulFF::BlankState(const Manager &mgr, const PhraseI return new (pool.Allocate()) SkeletonState(); } -Moses::FFState* SkeletonStatefulFF::EmptyHypothesisState(const Manager &mgr, const PhraseImpl &input) const +void SkeletonStatefulFF::EmptyHypothesisState(Moses::FFState &state, const Manager &mgr, const PhraseImpl &input) const { - MemPool &pool = mgr.GetPool(); - return new (pool.Allocate()) SkeletonState(0); + SkeletonState &stateCast = static_cast(state); + stateCast.targetLen = 0; } void diff --git a/contrib/other-builds/moses2/FF/SkeletonStatefulFF.h b/contrib/other-builds/moses2/FF/SkeletonStatefulFF.h index f49c56e07..c2954eee0 100644 --- a/contrib/other-builds/moses2/FF/SkeletonStatefulFF.h +++ b/contrib/other-builds/moses2/FF/SkeletonStatefulFF.h @@ -17,7 +17,7 @@ public: virtual ~SkeletonStatefulFF(); virtual Moses::FFState* BlankState(const Manager &mgr, const PhraseImpl &input) const; - virtual Moses::FFState* EmptyHypothesisState(const Manager &mgr, const PhraseImpl &input) const; + virtual void EmptyHypothesisState(Moses::FFState &state, const Manager &mgr, const PhraseImpl &input) const; virtual void EvaluateInIsolation(const System &system, diff --git a/contrib/other-builds/moses2/FF/StatefulFeatureFunction.h b/contrib/other-builds/moses2/FF/StatefulFeatureFunction.h index 7ff65faae..2d8b485db 100644 --- a/contrib/other-builds/moses2/FF/StatefulFeatureFunction.h +++ b/contrib/other-builds/moses2/FF/StatefulFeatureFunction.h @@ -28,7 +28,7 @@ public: virtual Moses::FFState* BlankState(const Manager &mgr, const PhraseImpl &input) const = 0; //! return the state associated with the empty hypothesis for a given sentence - virtual Moses::FFState* EmptyHypothesisState(const Manager &mgr, const PhraseImpl &input) const = 0; + virtual void EmptyHypothesisState(Moses::FFState &state, const Manager &mgr, const PhraseImpl &input) const = 0; virtual Moses::FFState* EvaluateWhenApplied(const Manager &mgr, const Hypothesis &hypo, diff --git a/contrib/other-builds/moses2/LM/KENLM.cpp b/contrib/other-builds/moses2/LM/KENLM.cpp index 3599708c4..3fa40278c 100644 --- a/contrib/other-builds/moses2/LM/KENLM.cpp +++ b/contrib/other-builds/moses2/LM/KENLM.cpp @@ -107,12 +107,10 @@ Moses::FFState* KENLM::BlankState(const Manager &mgr, const PhraseImpl &input) c } //! return the state associated with the empty hypothesis for a given sentence -Moses::FFState* KENLM::EmptyHypothesisState(const Manager &mgr, const PhraseImpl &input) const +void KENLM::EmptyHypothesisState(Moses::FFState &state, const Manager &mgr, const PhraseImpl &input) const { - MemPool &pool = mgr.GetPool(); - KenLMState *ret = new (pool.Allocate()) KenLMState(); - ret->state = m_ngram->BeginSentenceState(); - return ret; + KenLMState &stateCast = static_cast(state); + stateCast.state = m_ngram->BeginSentenceState(); } void diff --git a/contrib/other-builds/moses2/LM/KENLM.h b/contrib/other-builds/moses2/LM/KENLM.h index 919ce5542..934eacd3e 100644 --- a/contrib/other-builds/moses2/LM/KENLM.h +++ b/contrib/other-builds/moses2/LM/KENLM.h @@ -26,7 +26,7 @@ public: virtual Moses::FFState* BlankState(const Manager &mgr, const PhraseImpl &input) const; //! return the state associated with the empty hypothesis for a given sentence - virtual Moses::FFState* EmptyHypothesisState(const Manager &mgr, const PhraseImpl &input) const; + virtual void EmptyHypothesisState(Moses::FFState &state, const Manager &mgr, const PhraseImpl &input) const; virtual void EvaluateInIsolation(const System &system, diff --git a/contrib/other-builds/moses2/LM/LanguageModel.cpp b/contrib/other-builds/moses2/LM/LanguageModel.cpp index 941d220ad..a32955706 100644 --- a/contrib/other-builds/moses2/LM/LanguageModel.cpp +++ b/contrib/other-builds/moses2/LM/LanguageModel.cpp @@ -25,14 +25,6 @@ struct LMState : public Moses::PointerState // uninitialised } - LMState(MemPool &pool, const Moses::Factor *eos) - :PointerState(NULL) - { - numWords = 1; - lastWords = (const Moses::Factor**) pool.Allocate(sizeof(const Moses::Factor*)); - lastWords[0] = eos; - } - LMState(MemPool &pool, void *lms, const std::vector &context) :PointerState(lms) { @@ -43,6 +35,14 @@ struct LMState : public Moses::PointerState } } + void Init(MemPool &pool, const Moses::Factor *factor) + { + lmstate = NULL; + numWords = 1; + lastWords = (const Moses::Factor**) pool.Allocate(sizeof(const Moses::Factor*)); + lastWords[0] = factor; + } + size_t numWords; const Moses::Factor** lastWords; }; @@ -129,10 +129,12 @@ Moses::FFState* LanguageModel::BlankState(const Manager &mgr, const PhraseImpl & return new (pool.Allocate()) LMState(); } -Moses::FFState* LanguageModel::EmptyHypothesisState(const Manager &mgr, const PhraseImpl &input) const +void LanguageModel::EmptyHypothesisState(Moses::FFState &state, const Manager &mgr, const PhraseImpl &input) const { + LMState &stateCast = static_cast(state); + MemPool &pool = mgr.GetPool(); - return new (pool.Allocate()) LMState(pool, m_bos); + stateCast.Init(pool, m_bos); } void diff --git a/contrib/other-builds/moses2/LM/LanguageModel.h b/contrib/other-builds/moses2/LM/LanguageModel.h index 53c1a6763..f286ae93b 100644 --- a/contrib/other-builds/moses2/LM/LanguageModel.h +++ b/contrib/other-builds/moses2/LM/LanguageModel.h @@ -51,7 +51,7 @@ public: virtual void SetParameter(const std::string& key, const std::string& value); virtual Moses::FFState* BlankState(const Manager &mgr, const PhraseImpl &input) const; - virtual Moses::FFState* EmptyHypothesisState(const Manager &mgr, const PhraseImpl &input) const; + virtual void EmptyHypothesisState(Moses::FFState &state, const Manager &mgr, const PhraseImpl &input) const; virtual void EvaluateInIsolation(const System &system, diff --git a/contrib/other-builds/moses2/Search/Hypothesis.cpp b/contrib/other-builds/moses2/Search/Hypothesis.cpp index 73c9c1041..04eff6e6f 100644 --- a/contrib/other-builds/moses2/Search/Hypothesis.cpp +++ b/contrib/other-builds/moses2/Search/Hypothesis.cpp @@ -135,8 +135,8 @@ void Hypothesis::EmptyHypothesisState(const PhraseImpl &input) const std::vector &sfffs = m_mgr.GetSystem().featureFunctions.GetStatefulFeatureFunctions(); BOOST_FOREACH(const StatefulFeatureFunction *sfff, sfffs) { size_t statefulInd = sfff->GetStatefulInd(); - Moses::FFState *state = sfff->EmptyHypothesisState(m_mgr, input); - m_ffStates[statefulInd] = state; + Moses::FFState *state = m_ffStates[statefulInd]; + sfff->EmptyHypothesisState(*state, m_mgr, input); } }