Merge "Cleanup jni 1"

main
satok 2012-03-23 03:24:08 -07:00 committed by Android (Google) Code Review
commit 8980bd4a25
6 changed files with 26 additions and 33 deletions

View File

@ -205,9 +205,11 @@ public class BinaryDictionary extends Dictionary {
Arrays.fill(mInputCodes, WordComposer.NOT_A_CODE);
for (int i = 0; i < codesSize; i++) {
int[] alternatives = codes.getCodesAt(i);
System.arraycopy(alternatives, 0, mInputCodes, i * MAX_PROXIMITY_CHARS_SIZE,
Math.min(alternatives.length, MAX_PROXIMITY_CHARS_SIZE));
final int[] alternatives = codes.getCodesAt(i);
if (alternatives == null || alternatives.length < 1) {
continue;
}
mInputCodes[i] = alternatives[0];
}
Arrays.fill(outputChars, (char) 0);
Arrays.fill(scores, 0);

View File

@ -20,8 +20,6 @@ import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.keyboard.KeyDetector;
import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardActionListener;
import com.android.inputmethod.latin.spellcheck.AndroidSpellCheckerService;
import com.android.inputmethod.latin.spellcheck.SpellCheckerProximityInfo;
import java.util.ArrayList;
import java.util.Arrays;

View File

@ -129,7 +129,7 @@ bool ProximityInfo::hasSpaceProximity(const int x, const int y) const {
return false;
}
bool ProximityInfo::isOnKey(const int keyId, const int x, const int y) {
bool ProximityInfo::isOnKey(const int keyId, const int x, const int y) const {
if (keyId < 0) return true; // NOT_A_ID is -1, but return whenever < 0 just in case
const int left = mKeyXCoordinates[keyId];
const int top = mKeyYCoordinates[keyId];
@ -138,7 +138,7 @@ bool ProximityInfo::isOnKey(const int keyId, const int x, const int y) {
return left < right && top < bottom && x >= left && x < right && y >= top && y < bottom;
}
int ProximityInfo::squaredDistanceToEdge(const int keyId, const int x, const int y) {
int ProximityInfo::squaredDistanceToEdge(const int keyId, const int x, const int y) const {
if (keyId < 0) return true; // NOT_A_ID is -1, but return whenever < 0 just in case
const int left = mKeyXCoordinates[keyId];
const int top = mKeyYCoordinates[keyId];
@ -152,7 +152,7 @@ int ProximityInfo::squaredDistanceToEdge(const int keyId, const int x, const int
}
void ProximityInfo::calculateNearbyKeyCodes(
const int x, const int y, const int32_t primaryKey, int *inputCodes) {
const int x, const int y, const int32_t primaryKey, int *inputCodes) const {
int insertPos = 0;
inputCodes[insertPos++] = primaryKey;
const int startIndex = getStartIndexFromCoordinates(x, y);
@ -219,7 +219,7 @@ void ProximityInfo::setInputParams(const int32_t* inputCodes, const int inputLen
MAX_WORD_LENGTH_INTERNAL * MAX_PROXIMITY_CHARS_SIZE * sizeof(mInputCodes[0]));
for (int i = 0; i < inputLength; ++i) {
const int32_t primaryKey = inputCodes[i * MAX_PROXIMITY_CHARS_SIZE];
const int32_t primaryKey = inputCodes[i];
const int x = xCoordinates[i];
const int y = yCoordinates[i];
int *proximities = &mInputCodes[i * MAX_PROXIMITY_CHARS_SIZE];

View File

@ -92,10 +92,10 @@ class ProximityInfo {
// the radius of the key is assigned to zero.
return mSweetSpotRadii[keyIndex] > 0.0;
}
bool isOnKey(const int keyId, const int x, const int y);
int squaredDistanceToEdge(const int keyId, const int x, const int y);
bool isOnKey(const int keyId, const int x, const int y) const;
int squaredDistanceToEdge(const int keyId, const int x, const int y) const;
void calculateNearbyKeyCodes(
const int x, const int y, const int32_t primaryKey, int *inputCodes);
const int x, const int y, const int32_t primaryKey, int *inputCodes) const;
const int MAX_PROXIMITY_CHARS_SIZE;
const int KEYBOARD_WIDTH;

View File

@ -43,11 +43,11 @@ UnigramDictionary::UnigramDictionary(const uint8_t* const streamStart, int typed
int fullWordMultiplier, int maxWordLength, int maxWords, int maxProximityChars,
const bool isLatestDictVersion)
: DICT_ROOT(streamStart), MAX_WORD_LENGTH(maxWordLength), MAX_WORDS(maxWords),
MAX_PROXIMITY_CHARS(maxProximityChars), IS_LATEST_DICT_VERSION(isLatestDictVersion),
IS_LATEST_DICT_VERSION(isLatestDictVersion),
TYPED_LETTER_MULTIPLIER(typedLetterMultiplier), FULL_WORD_MULTIPLIER(fullWordMultiplier),
// TODO : remove this variable.
ROOT_POS(0),
BYTES_IN_ONE_CHAR(MAX_PROXIMITY_CHARS * sizeof(int)),
BYTES_IN_ONE_CHAR(sizeof(int)),
MAX_DIGRAPH_SEARCH_DEPTH(DEFAULT_MAX_DIGRAPH_SEARCH_DEPTH) {
if (DEBUG_DICT) {
AKLOGI("UnigramDictionary - constructor");
@ -57,9 +57,8 @@ UnigramDictionary::UnigramDictionary(const uint8_t* const streamStart, int typed
UnigramDictionary::~UnigramDictionary() {
}
static inline unsigned int getCodesBufferSize(const int *codes, const int codesSize,
const int MAX_PROXIMITY_CHARS) {
return sizeof(*codes) * MAX_PROXIMITY_CHARS * codesSize;
static inline unsigned int getCodesBufferSize(const int *codes, const int codesSize) {
return sizeof(*codes) * codesSize;
}
// TODO: This needs to take a const unsigned short* and not tinker with its contents
@ -77,7 +76,7 @@ int UnigramDictionary::getDigraphReplacement(const int *codes, const int i, cons
// Search for the first char of some digraph
int lastDigraphIndex = -1;
const int thisChar = codes[i * MAX_PROXIMITY_CHARS];
const int thisChar = codes[i];
for (lastDigraphIndex = digraphsSize - 1; lastDigraphIndex >= 0; --lastDigraphIndex) {
if (thisChar == digraphs[lastDigraphIndex].first) break;
}
@ -85,7 +84,7 @@ int UnigramDictionary::getDigraphReplacement(const int *codes, const int i, cons
if (lastDigraphIndex < 0) return 0;
// It's an interesting digraph if the second char matches too.
if (digraphs[lastDigraphIndex].second == codes[(i + 1) * MAX_PROXIMITY_CHARS]) {
if (digraphs[lastDigraphIndex].second == codes[i + 1]) {
return digraphs[lastDigraphIndex].replacement;
} else {
return 0;
@ -106,7 +105,7 @@ void UnigramDictionary::getWordWithDigraphSuggestionsRec(ProximityInfo *proximit
WordsPriorityQueuePool *queuePool,
const digraph_t* const digraphs, const unsigned int digraphsSize) {
const int startIndex = (codesDest - codesBuffer) / MAX_PROXIMITY_CHARS;
const int startIndex = codesDest - codesBuffer;
if (currentDepth < MAX_DIGRAPH_SEARCH_DEPTH) {
for (int i = 0; i < codesRemain; ++i) {
xCoordinatesBuffer[startIndex + i] = xcoordinates[codesBufferSize - codesRemain + i];
@ -130,19 +129,18 @@ void UnigramDictionary::getWordWithDigraphSuggestionsRec(ProximityInfo *proximit
replacementCodePoint;
getWordWithDigraphSuggestionsRec(proximityInfo, xcoordinates, ycoordinates,
codesBuffer, xCoordinatesBuffer, yCoordinatesBuffer, codesBufferSize, flags,
codesSrc + (i + 1) * MAX_PROXIMITY_CHARS, codesRemain - i - 1,
currentDepth + 1, codesDest + i * MAX_PROXIMITY_CHARS, correction,
codesSrc + i + 1, codesRemain - i - 1,
currentDepth + 1, codesDest + i, correction,
queuePool, digraphs, digraphsSize);
// Copy the second char of the digraph in place, then continue processing on
// the remaining part of the word.
// In our example, after "pru" in the buffer copy the "e", and continue on "fen"
memcpy(codesDest + i * MAX_PROXIMITY_CHARS, codesSrc + i * MAX_PROXIMITY_CHARS,
BYTES_IN_ONE_CHAR);
memcpy(codesDest + i, codesSrc + i, BYTES_IN_ONE_CHAR);
getWordWithDigraphSuggestionsRec(proximityInfo, xcoordinates, ycoordinates,
codesBuffer, xCoordinatesBuffer, yCoordinatesBuffer, codesBufferSize, flags,
codesSrc + i * MAX_PROXIMITY_CHARS, codesRemain - i, currentDepth + 1,
codesDest + i * MAX_PROXIMITY_CHARS, correction, queuePool,
codesSrc + i, codesRemain - i, currentDepth + 1,
codesDest + i, correction, queuePool,
digraphs, digraphsSize);
return;
}
@ -177,7 +175,7 @@ int UnigramDictionary::getSuggestions(ProximityInfo *proximityInfo,
Correction* masterCorrection = correction;
if (REQUIRES_GERMAN_UMLAUT_PROCESSING & flags)
{ // Incrementally tune the word and try all possibilities
int codesBuffer[getCodesBufferSize(codes, codesSize, MAX_PROXIMITY_CHARS)];
int codesBuffer[getCodesBufferSize(codes, codesSize)];
int xCoordinatesBuffer[codesSize];
int yCoordinatesBuffer[codesSize];
getWordWithDigraphSuggestionsRec(proximityInfo, xcoordinates, ycoordinates, codesBuffer,
@ -427,7 +425,7 @@ bool UnigramDictionary::getSubStringSuggestion(
if (inputWordStartPos > 0) {
const int offset = inputWordStartPos;
initSuggestions(proximityInfo, &xcoordinates[offset], &ycoordinates[offset],
codes + offset * MAX_PROXIMITY_CHARS, inputWordLength, correction);
codes + offset, inputWordLength, correction);
queuePool->clearSubQueue(currentWordIndex);
getSuggestionCandidates(useFullEditDistance, inputWordLength, correction,
queuePool, false, MAX_ERRORS_FOR_TWO_WORDS, currentWordIndex);
@ -585,10 +583,6 @@ void UnigramDictionary::getSplitMultipleWordsSuggestions(ProximityInfo *proximit
Correction *correction, WordsPriorityQueuePool* queuePool,
const bool hasAutoCorrectionCandidate) {
if (inputLength >= MAX_WORD_LENGTH) return;
if (DEBUG_DICT) {
// MAX_PROXIMITY_CHARS_SIZE in ProximityInfo.java should be 16
assert(MAX_PROXIMITY_CHARS == 16);
}
if (DEBUG_DICT) {
AKLOGI("--- Suggest multiple words");
}

View File

@ -143,7 +143,6 @@ class UnigramDictionary {
const uint8_t* const DICT_ROOT;
const int MAX_WORD_LENGTH;
const int MAX_WORDS;
const int MAX_PROXIMITY_CHARS;
const bool IS_LATEST_DICT_VERSION;
const int TYPED_LETTER_MULTIPLIER;
const int FULL_WORD_MULTIPLIER;