From 162c211b44c1546b2e9be36e0cec50de497217a9 Mon Sep 17 00:00:00 2001 From: Ken Wakasa Date: Fri, 24 Aug 2012 14:51:15 +0900 Subject: [PATCH] Address warnings by -Weffc++ Change-Id: Icd60f1ed2ace0b975d8785bc8a386c7944846075 --- ...oid_inputmethod_latin_BinaryDictionary.cpp | 8 +++---- native/jni/src/correction.cpp | 3 --- native/jni/src/correction.h | 21 +++++++++++++++++-- native/jni/src/dictionary.cpp | 19 ++++++++--------- .../jni/src/gesture/gesture_decoder_wrapper.h | 4 ++-- .../src/gesture/incremental_decoder_wrapper.h | 4 ++-- native/jni/src/proximity_info.cpp | 13 +++++++----- native/jni/src/proximity_info.h | 6 ++---- native/jni/src/proximity_info_state.h | 14 ++++++++++++- native/jni/src/terminal_attributes.h | 21 +++++++++---------- native/jni/src/words_priority_queue.h | 11 +++++----- native/jni/src/words_priority_queue_pool.h | 11 +++++----- 12 files changed, 80 insertions(+), 55 deletions(-) diff --git a/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp b/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp index 6a0a7c2a0..a20958a88 100644 --- a/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp +++ b/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp @@ -172,10 +172,10 @@ static int latinime_BinaryDictionary_getSuggestions(JNIEnv *env, jobject object, int spaceIndices[spaceIndicesLength]; const jsize outputTypesLength = env->GetArrayLength(outputTypesArray); int outputTypes[outputTypesLength]; - memset(outputChars, 0, outputCharsLength * sizeof(outputChars[0])); - memset(scores, 0, scoresLength * sizeof(scores[0])); - memset(spaceIndices, 0, spaceIndicesLength * sizeof(spaceIndices[0])); - memset(outputTypes, 0, outputTypesLength * sizeof(outputTypes[0])); + memset(outputChars, 0, sizeof(outputChars)); + memset(scores, 0, sizeof(scores)); + memset(spaceIndices, 0, sizeof(spaceIndices)); + memset(outputTypes, 0, sizeof(outputTypes)); int count; if (isGesture || arraySize > 0) { diff --git a/native/jni/src/correction.cpp b/native/jni/src/correction.cpp index 342dec9a3..9ad65b09d 100644 --- a/native/jni/src/correction.cpp +++ b/native/jni/src/correction.cpp @@ -627,9 +627,6 @@ Correction::CorrectionType Correction::processCharAndCalcState( } } -Correction::~Correction() { -} - inline static int getQuoteCount(const unsigned short *word, const int length) { int quoteCount = 0; for (int i = 0; i < length; ++i) { diff --git a/native/jni/src/correction.h b/native/jni/src/correction.h index c90c8d553..f016d5453 100644 --- a/native/jni/src/correction.h +++ b/native/jni/src/correction.h @@ -18,6 +18,7 @@ #define LATINIME_CORRECTION_H #include +#include // for memset() #include #include "correction_state.h" @@ -38,8 +39,24 @@ class Correction { NOT_ON_TERMINAL } CorrectionType; - Correction() {}; - virtual ~Correction(); + Correction() + : mProximityInfo(0), mUseFullEditDistance(false), mDoAutoCompletion(false), + mMaxEditDistance(0), mMaxDepth(0), mInputSize(0), mSpaceProximityPos(0), + mMissingSpacePos(0), mTerminalInputIndex(0), mTerminalOutputIndex(0), mMaxErrors(0), + mTotalTraverseCount(0), mNeedsToTraverseAllNodes(false), mOutputIndex(0), + mInputIndex(0), mEquivalentCharCount(0), mProximityCount(0), mExcessiveCount(0), + mTransposedCount(0), mSkippedCount(0), mTransposedPos(0), mExcessivePos(0), + mSkipPos(0), mLastCharExceeded(false), mMatching(false), mProximityMatching(false), + mAdditionalProximityMatching(false), mExceeding(false), mTransposing(false), + mSkipping(false), mProximityInfoState() { + memset(mWord, 0, sizeof(mWord)); + memset(mDistances, 0, sizeof(mDistances)); + memset(mEditDistanceTable, 0, sizeof(mEditDistanceTable)); + // NOTE: mCorrectionStates is an array of instances. + // No need to initialize it explicitly here. + } + + virtual ~Correction() {} void resetCorrection(); void initCorrection( const ProximityInfo *pi, const int inputSize, const int maxWordLength); diff --git a/native/jni/src/dictionary.cpp b/native/jni/src/dictionary.cpp index 8ce8c8ba6..2fbe83e86 100644 --- a/native/jni/src/dictionary.cpp +++ b/native/jni/src/dictionary.cpp @@ -30,11 +30,15 @@ namespace latinime { // TODO: Change the type of all keyCodes to uint32_t Dictionary::Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust, - int typedLetterMultiplier, int fullWordMultiplier, - int maxWordLength, int maxWords, int maxPredictions) - : mDict(static_cast(dict)), - mOffsetDict((static_cast(dict)) + BinaryFormat::getHeaderSize(mDict)), - mDictSize(dictSize), mMmapFd(mmapFd), mDictBufAdjust(dictBufAdjust) { + int typedLetterMultiplier, int fullWordMultiplier, int maxWordLength, int maxWords, + int maxPredictions) + : mDict(static_cast(dict)), + mOffsetDict((static_cast(dict)) + BinaryFormat::getHeaderSize(mDict)), + mDictSize(dictSize), mMmapFd(mmapFd), mDictBufAdjust(dictBufAdjust), + mUnigramDictionary(new UnigramDictionary(mOffsetDict, typedLetterMultiplier, + fullWordMultiplier, maxWordLength, maxWords, BinaryFormat::getFlags(mDict))), + mBigramDictionary(new BigramDictionary(mOffsetDict, maxWordLength, maxPredictions)), + mGestureDecoder(new GestureDecoderWrapper(maxWordLength, maxWords)) { if (DEBUG_DICT) { if (MAX_WORD_LENGTH_INTERNAL < maxWordLength) { AKLOGI("Max word length (%d) is greater than %d", @@ -42,11 +46,6 @@ Dictionary::Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust, AKLOGI("IN NATIVE SUGGEST Version: %d", (mDict[0] & 0xFF)); } } - const unsigned int options = BinaryFormat::getFlags(mDict); - mUnigramDictionary = new UnigramDictionary(mOffsetDict, typedLetterMultiplier, - fullWordMultiplier, maxWordLength, maxWords, options); - mBigramDictionary = new BigramDictionary(mOffsetDict, maxWordLength, maxPredictions); - mGestureDecoder = new GestureDecoderWrapper(maxWordLength, maxWords); } Dictionary::~Dictionary() { diff --git a/native/jni/src/gesture/gesture_decoder_wrapper.h b/native/jni/src/gesture/gesture_decoder_wrapper.h index 2f6220b92..92e1ded49 100644 --- a/native/jni/src/gesture/gesture_decoder_wrapper.h +++ b/native/jni/src/gesture/gesture_decoder_wrapper.h @@ -29,8 +29,8 @@ class ProximityInfo; class GestureDecoderWrapper : public IncrementalDecoderInterface { public: - GestureDecoderWrapper(const int maxWordLength, const int maxWords) { - mIncrementalDecoderInterface = getGestureDecoderInstance(maxWordLength, maxWords); + GestureDecoderWrapper(const int maxWordLength, const int maxWords) + : mIncrementalDecoderInterface(getGestureDecoderInstance(maxWordLength, maxWords)) { } virtual ~GestureDecoderWrapper() { diff --git a/native/jni/src/gesture/incremental_decoder_wrapper.h b/native/jni/src/gesture/incremental_decoder_wrapper.h index 1f4d8a047..da7afdb8a 100644 --- a/native/jni/src/gesture/incremental_decoder_wrapper.h +++ b/native/jni/src/gesture/incremental_decoder_wrapper.h @@ -29,8 +29,8 @@ class ProximityInfo; class IncrementalDecoderWrapper : public IncrementalDecoderInterface { public: - IncrementalDecoderWrapper(const int maxWordLength, const int maxWords) { - mIncrementalDecoderInterface = getIncrementalDecoderInstance(maxWordLength, maxWords); + IncrementalDecoderWrapper(const int maxWordLength, const int maxWords) + : mIncrementalDecoderInterface(getIncrementalDecoderInstance(maxWordLength, maxWords)) { } virtual ~IncrementalDecoderWrapper() { diff --git a/native/jni/src/proximity_info.cpp b/native/jni/src/proximity_info.cpp index 1b9bac0f0..e681f6f97 100644 --- a/native/jni/src/proximity_info.cpp +++ b/native/jni/src/proximity_info.cpp @@ -29,6 +29,9 @@ namespace latinime { +/* static */ const int ProximityInfo::NOT_A_CODE = -1; +/* static */ const float ProximityInfo::NOT_A_DISTANCE_FLOAT = -1.0f; + static inline void safeGetOrFillZeroIntArrayRegion(JNIEnv *env, jintArray jArray, jsize len, jint *buffer) { if (jArray && buffer) { @@ -54,16 +57,17 @@ ProximityInfo::ProximityInfo(JNIEnv *env, const jstring localeJStr, const int ma const jintArray keyWidths, const jintArray keyHeights, const jintArray keyCharCodes, const jfloatArray sweetSpotCenterXs, const jfloatArray sweetSpotCenterYs, const jfloatArray sweetSpotRadii) - : MAX_PROXIMITY_CHARS_SIZE(maxProximityCharsSize), KEYBOARD_WIDTH(keyboardWidth), - KEYBOARD_HEIGHT(keyboardHeight), GRID_WIDTH(gridWidth), GRID_HEIGHT(gridHeight), - MOST_COMMON_KEY_WIDTH(mostCommonKeyWidth), + : MAX_PROXIMITY_CHARS_SIZE(maxProximityCharsSize), GRID_WIDTH(gridWidth), + GRID_HEIGHT(gridHeight), MOST_COMMON_KEY_WIDTH(mostCommonKeyWidth), MOST_COMMON_KEY_WIDTH_SQUARE(mostCommonKeyWidth * mostCommonKeyWidth), CELL_WIDTH((keyboardWidth + gridWidth - 1) / gridWidth), CELL_HEIGHT((keyboardHeight + gridHeight - 1) / gridHeight), KEY_COUNT(min(keyCount, MAX_KEY_COUNT_IN_A_KEYBOARD)), HAS_TOUCH_POSITION_CORRECTION_DATA(keyCount > 0 && keyXCoordinates && keyYCoordinates && keyWidths && keyHeights && keyCharCodes && sweetSpotCenterXs - && sweetSpotCenterYs && sweetSpotRadii) { + && sweetSpotCenterYs && sweetSpotRadii), + mProximityCharsArray(new int32_t[GRID_WIDTH * GRID_HEIGHT * MAX_PROXIMITY_CHARS_SIZE + /* proximityGridLength */]) { const int proximityGridLength = GRID_WIDTH * GRID_HEIGHT * MAX_PROXIMITY_CHARS_SIZE; if (DEBUG_PROXIMITY_INFO) { AKLOGI("Create proximity info array %d", proximityGridLength); @@ -75,7 +79,6 @@ ProximityInfo::ProximityInfo(JNIEnv *env, const jstring localeJStr, const int ma } memset(mLocaleStr, 0, sizeof(mLocaleStr)); env->GetStringUTFRegion(localeJStr, 0, env->GetStringLength(localeJStr), mLocaleStr); - mProximityCharsArray = new int32_t[proximityGridLength]; safeGetOrFillZeroIntArrayRegion(env, proximityChars, proximityGridLength, mProximityCharsArray); safeGetOrFillZeroIntArrayRegion(env, keyXCoordinates, KEY_COUNT, mKeyXCoordinates); safeGetOrFillZeroIntArrayRegion(env, keyYCoordinates, KEY_COUNT, mKeyYCoordinates); diff --git a/native/jni/src/proximity_info.h b/native/jni/src/proximity_info.h index 7ee633ba8..822909b7a 100644 --- a/native/jni/src/proximity_info.h +++ b/native/jni/src/proximity_info.h @@ -108,8 +108,8 @@ class ProximityInfo { static const int MAX_KEY_COUNT_IN_A_KEYBOARD = 64; // The upper limit of the char code in mCodeToKeyIndex static const int MAX_CHAR_CODE = 127; - static const float NOT_A_DISTANCE_FLOAT = -1.0f; - static const int NOT_A_CODE = -1; + static const int NOT_A_CODE; + static const float NOT_A_DISTANCE_FLOAT; int getStartIndexFromCoordinates(const int x, const int y) const; void initializeCodeToKeyIndex(); @@ -129,8 +129,6 @@ class ProximityInfo { } const int MAX_PROXIMITY_CHARS_SIZE; - const int KEYBOARD_WIDTH; - const int KEYBOARD_HEIGHT; const int GRID_WIDTH; const int GRID_HEIGHT; const int MOST_COMMON_KEY_WIDTH; diff --git a/native/jni/src/proximity_info_state.h b/native/jni/src/proximity_info_state.h index 687a552c1..13b080705 100644 --- a/native/jni/src/proximity_info_state.h +++ b/native/jni/src/proximity_info_state.h @@ -17,6 +17,7 @@ #ifndef LATINIME_PROXIMITY_INFO_STATE_H #define LATINIME_PROXIMITY_INFO_STATE_H +#include // for memset() #include #include #include @@ -49,7 +50,18 @@ class ProximityInfoState { ///////////////////////////////////////// // Defined here // ///////////////////////////////////////// - ProximityInfoState() {}; + ProximityInfoState() + : mProximityInfo(0), mMaxPointToKeyLength(0), + mHasTouchPositionCorrectionData(false), mMostCommonKeyWidthSquare(0), mLocaleStr(), + mKeyCount(0), mCellHeight(0), mCellWidth(0), mGridHeight(0), mGridWidth(0), + mInputXs(), mInputYs(), mTimes(), mDistanceCache(), mLengthCache(), + mTouchPositionCorrectionEnabled(false), mInputSize(0) { + memset(mInputCodes, 0, sizeof(mInputCodes)); + memset(mNormalizedSquaredDistances, 0, sizeof(mNormalizedSquaredDistances)); + memset(mPrimaryInputWord, 0, sizeof(mPrimaryInputWord)); + } + + virtual ~ProximityInfoState() {} inline unsigned short getPrimaryCharAt(const int index) const { return getProximityCharsAt(index)[0]; diff --git a/native/jni/src/terminal_attributes.h b/native/jni/src/terminal_attributes.h index 1ae9c7cbb..34ab8f0ef 100644 --- a/native/jni/src/terminal_attributes.h +++ b/native/jni/src/terminal_attributes.h @@ -30,13 +30,13 @@ class TerminalAttributes { public: class ShortcutIterator { const uint8_t *const mDict; - bool mHasNextShortcutTarget; int mPos; + bool mHasNextShortcutTarget; public: - ShortcutIterator(const uint8_t *dict, const int pos, const uint8_t flags) : mDict(dict), - mPos(pos) { - mHasNextShortcutTarget = (0 != (flags & BinaryFormat::FLAG_HAS_SHORTCUT_TARGETS)); + ShortcutIterator(const uint8_t *dict, const int pos, const uint8_t flags) + : mDict(dict), mPos(pos), + mHasNextShortcutTarget(0 != (flags & BinaryFormat::FLAG_HAS_SHORTCUT_TARGETS)) { } inline bool hasNextShortcutTarget() const { @@ -62,13 +62,6 @@ class TerminalAttributes { } }; - private: - DISALLOW_IMPLICIT_CONSTRUCTORS(TerminalAttributes); - const uint8_t *const mDict; - const uint8_t mFlags; - const int mStartPos; - - public: TerminalAttributes(const uint8_t *const dict, const uint8_t flags, const int pos) : mDict(dict), mFlags(flags), mStartPos(pos) { } @@ -78,6 +71,12 @@ class TerminalAttributes { // skipped quickly, so we ignore it. return ShortcutIterator(mDict, mStartPos + BinaryFormat::SHORTCUT_LIST_SIZE_SIZE, mFlags); } + + private: + DISALLOW_IMPLICIT_CONSTRUCTORS(TerminalAttributes); + const uint8_t *const mDict; + const uint8_t mFlags; + const int mStartPos; }; } // namespace latinime #endif // LATINIME_TERMINAL_ATTRIBUTES_H diff --git a/native/jni/src/words_priority_queue.h b/native/jni/src/words_priority_queue.h index 1e4e00a23..19efa5da3 100644 --- a/native/jni/src/words_priority_queue.h +++ b/native/jni/src/words_priority_queue.h @@ -44,17 +44,16 @@ class WordsPriorityQueue { } }; - WordsPriorityQueue(int maxWords, int maxWordLength) : - MAX_WORDS((unsigned int) maxWords), MAX_WORD_LENGTH( - (unsigned int) maxWordLength) { - mSuggestedWords = new SuggestedWord[maxWordLength]; + WordsPriorityQueue(int maxWords, int maxWordLength) + : mSuggestions(), MAX_WORDS(static_cast(maxWords)), + MAX_WORD_LENGTH(static_cast(maxWordLength)), + mSuggestedWords(new SuggestedWord[maxWordLength]), mHighestSuggestedWord(0) { for (int i = 0; i < maxWordLength; ++i) { mSuggestedWords[i].mUsed = false; } - mHighestSuggestedWord = 0; } - ~WordsPriorityQueue() { + virtual ~WordsPriorityQueue() { delete[] mSuggestedWords; } diff --git a/native/jni/src/words_priority_queue_pool.h b/native/jni/src/words_priority_queue_pool.h index 38887291e..1112229da 100644 --- a/native/jni/src/words_priority_queue_pool.h +++ b/native/jni/src/words_priority_queue_pool.h @@ -24,9 +24,10 @@ namespace latinime { class WordsPriorityQueuePool { public: - WordsPriorityQueuePool(int mainQueueMaxWords, int subQueueMaxWords, int maxWordLength) { - // Note: using placement new() requires the caller to call the destructor explicitly. - mMasterQueue = new(mMasterQueueBuf) WordsPriorityQueue(mainQueueMaxWords, maxWordLength); + WordsPriorityQueuePool(int mainQueueMaxWords, int subQueueMaxWords, int maxWordLength) + // Note: using placement new() requires the caller to call the destructor explicitly. + : mMasterQueue(new(mMasterQueueBuf) WordsPriorityQueue( + mainQueueMaxWords, maxWordLength)) { for (int i = 0, subQueueBufOffset = 0; i < MULTIPLE_WORDS_SUGGESTION_MAX_WORDS * SUB_QUEUE_MAX_COUNT; ++i, subQueueBufOffset += sizeof(WordsPriorityQueue)) { @@ -88,8 +89,8 @@ class WordsPriorityQueuePool { WordsPriorityQueue *mMasterQueue; WordsPriorityQueue *mSubQueues[SUB_QUEUE_MAX_COUNT * MULTIPLE_WORDS_SUGGESTION_MAX_WORDS]; char mMasterQueueBuf[sizeof(WordsPriorityQueue)]; - char mSubQueueBuf[MULTIPLE_WORDS_SUGGESTION_MAX_WORDS - * SUB_QUEUE_MAX_COUNT * sizeof(WordsPriorityQueue)]; + char mSubQueueBuf[SUB_QUEUE_MAX_COUNT * MULTIPLE_WORDS_SUGGESTION_MAX_WORDS + * sizeof(WordsPriorityQueue)]; }; } // namespace latinime #endif // LATINIME_WORDS_PRIORITY_QUEUE_POOL_H