From d6fdd58cc0dcdd1e1b1018de10a30e423494a8fd Mon Sep 17 00:00:00 2001 From: Keisuke Kuroyanagi Date: Thu, 15 May 2014 15:36:56 +0900 Subject: [PATCH] Cleanup DicTraverseSession. Change-Id: I953665e1958e7214e9365e2bc9d3f3843016dc81 --- ...com_android_inputmethod_latin_BinaryDictionary.cpp | 4 +++- ...m_android_inputmethod_latin_DicTraverseSession.cpp | 9 +++++---- native/jni/src/suggest/core/dictionary/dictionary.cpp | 3 +-- .../src/suggest/core/session/dic_traverse_session.h | 11 ----------- 4 files changed, 9 insertions(+), 18 deletions(-) diff --git a/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp b/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp index fdb876409..e79fb71b8 100644 --- a/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp +++ b/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp @@ -190,7 +190,9 @@ static void latinime_BinaryDictionary_getSuggestions(JNIEnv *env, jclass clazz, ProximityInfo *pInfo = reinterpret_cast(proximityInfo); DicTraverseSession *traverseSession = reinterpret_cast(dicTraverseSession); - + if (!traverseSession) { + return; + } // Input values int xCoordinates[inputSize]; int yCoordinates[inputSize]; diff --git a/native/jni/com_android_inputmethod_latin_DicTraverseSession.cpp b/native/jni/com_android_inputmethod_latin_DicTraverseSession.cpp index 386643332..5cc20aa70 100644 --- a/native/jni/com_android_inputmethod_latin_DicTraverseSession.cpp +++ b/native/jni/com_android_inputmethod_latin_DicTraverseSession.cpp @@ -34,16 +34,17 @@ static jlong latinime_setDicTraverseSession(JNIEnv *env, jclass clazz, jstring l static void latinime_initDicTraverseSession(JNIEnv *env, jclass clazz, jlong traverseSession, jlong dictionary, jintArray previousWord, jint previousWordLength) { DicTraverseSession *ts = reinterpret_cast(traverseSession); + if (!ts) { + return; + } Dictionary *dict = reinterpret_cast(dictionary); if (!previousWord) { - DicTraverseSession::initSessionInstance( - ts, dict, 0 /* prevWord */, 0 /* prevWordLength*/, 0 /* suggestOptions */); + ts->init(dict, 0 /* prevWord */, 0 /* prevWordLength*/, 0 /* suggestOptions */); return; } int prevWord[previousWordLength]; env->GetIntArrayRegion(previousWord, 0, previousWordLength, prevWord); - DicTraverseSession::initSessionInstance( - ts, dict, prevWord, previousWordLength, 0 /* suggestOptions */); + ts->init(dict, prevWord, previousWordLength, 0 /* suggestOptions */); } static void latinime_releaseDicTraverseSession(JNIEnv *env, jclass clazz, jlong traverseSession) { diff --git a/native/jni/src/suggest/core/dictionary/dictionary.cpp b/native/jni/src/suggest/core/dictionary/dictionary.cpp index fdc893653..aa52e63c0 100644 --- a/native/jni/src/suggest/core/dictionary/dictionary.cpp +++ b/native/jni/src/suggest/core/dictionary/dictionary.cpp @@ -48,8 +48,7 @@ void Dictionary::getSuggestions(ProximityInfo *proximityInfo, DicTraverseSession const SuggestOptions *const suggestOptions, const float languageWeight, SuggestionResults *const outSuggestionResults) const { TimeKeeper::setCurrentTime(); - DicTraverseSession::initSessionInstance( - traverseSession, this, prevWordCodePoints, prevWordLength, suggestOptions); + traverseSession->init(this, prevWordCodePoints, prevWordLength, suggestOptions); const auto &suggest = suggestOptions->isGesture() ? mGestureSuggest : mTypingSuggest; suggest->getSuggestions(proximityInfo, traverseSession, xcoordinates, ycoordinates, times, pointerIds, inputCodePoints, inputSize, diff --git a/native/jni/src/suggest/core/session/dic_traverse_session.h b/native/jni/src/suggest/core/session/dic_traverse_session.h index 843ca85a0..50bffebac 100644 --- a/native/jni/src/suggest/core/session/dic_traverse_session.h +++ b/native/jni/src/suggest/core/session/dic_traverse_session.h @@ -44,15 +44,6 @@ class DicTraverseSession { dictSize >= DICTIONARY_SIZE_THRESHOLD_TO_USE_LARGE_CACHE_FOR_SUGGESTION); } - static AK_FORCE_INLINE void initSessionInstance(DicTraverseSession *traverseSession, - const Dictionary *const dictionary, const int *prevWord, const int prevWordLength, - const SuggestOptions *const suggestOptions) { - if (traverseSession) { - DicTraverseSession *tSession = static_cast(traverseSession); - tSession->init(dictionary, prevWord, prevWordLength, suggestOptions); - } - } - static AK_FORCE_INLINE void releaseSessionInstance(DicTraverseSession *traverseSession) { delete traverseSession; } @@ -86,8 +77,6 @@ class DicTraverseSession { const ProximityInfo *getProximityInfo() const { return mProximityInfo; } const SuggestOptions *getSuggestOptions() const { return mSuggestOptions; } int getPrevWordPtNodePos() const { return mPrevWordPtNodePos; } - // TODO: REMOVE - void setPrevWordPtNodePos(const int ptNodePos) { mPrevWordPtNodePos = ptNodePos; } DicNodesCache *getDicTraverseCache() { return &mDicNodesCache; } MultiBigramMap *getMultiBigramMap() { return &mMultiBigramMap; } const ProximityInfoState *getProximityInfoState(int id) const {