am 162c211b: Address warnings by -Weffc++
* commit '162c211b44c1546b2e9be36e0cec50de497217a9': Address warnings by -Weffc++main
commit
c4d9250202
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#define LATINIME_CORRECTION_H
|
||||
|
||||
#include <cassert>
|
||||
#include <cstring> // for memset()
|
||||
#include <stdint.h>
|
||||
|
||||
#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);
|
||||
|
|
|
@ -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)
|
||||
int typedLetterMultiplier, int fullWordMultiplier, int maxWordLength, int maxWords,
|
||||
int maxPredictions)
|
||||
: mDict(static_cast<unsigned char *>(dict)),
|
||||
mOffsetDict((static_cast<unsigned char *>(dict)) + BinaryFormat::getHeaderSize(mDict)),
|
||||
mDictSize(dictSize), mMmapFd(mmapFd), mDictBufAdjust(dictBufAdjust) {
|
||||
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() {
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#ifndef LATINIME_PROXIMITY_INFO_STATE_H
|
||||
#define LATINIME_PROXIMITY_INFO_STATE_H
|
||||
|
||||
#include <cstring> // for memset()
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
@ -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];
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<unsigned int>(maxWords)),
|
||||
MAX_WORD_LENGTH(static_cast<unsigned int>(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;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,9 +24,10 @@ namespace latinime {
|
|||
|
||||
class WordsPriorityQueuePool {
|
||||
public:
|
||||
WordsPriorityQueuePool(int mainQueueMaxWords, int subQueueMaxWords, int 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);
|
||||
: 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
|
||||
|
|
Loading…
Reference in New Issue