Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b7d7c5a3 authored by Jean Chalard's avatar Jean Chalard
Browse files

Make a constant really constant (A104)

Change-Id: Ied1f9f96a574b1e6a8ee0a71bfb1604d9c962e1c
parent 8f7f04fe
Loading
Loading
Loading
Loading
+8 −7
Original line number Diff line number Diff line
@@ -45,8 +45,8 @@ public class BinaryDictionary extends Dictionary {
    public static final int MAX_SPACES = 16;

    private static final String TAG = "BinaryDictionary";
    private static final int MAX_BIGRAMS = 60;
    private static final int MAX_RESULTS = MAX_BIGRAMS > MAX_WORDS ? MAX_BIGRAMS : MAX_WORDS;
    private static final int MAX_PREDICTIONS = 60;
    private static final int MAX_RESULTS = Math.max(MAX_PREDICTIONS, MAX_WORDS);

    private static final int TYPED_LETTER_MULTIPLIER = 2;

@@ -82,7 +82,8 @@ public class BinaryDictionary extends Dictionary {
    }

    private native long openNative(String sourceDir, long dictOffset, long dictSize,
            int typedLetterMultiplier, int fullWordMultiplier, int maxWordLength, int maxWords);
            int typedLetterMultiplier, int fullWordMultiplier, int maxWordLength, int maxWords,
            int maxPredictions);
    private native void closeNative(long dict);
    private native int getFrequencyNative(long dict, int[] word, int wordLength);
    private native boolean isValidBigramNative(long dict, int[] word1, int[] word2);
@@ -100,8 +101,8 @@ public class BinaryDictionary extends Dictionary {
            char[] before, int beforeLength, char[] after, int afterLength);

    private final void loadDictionary(String path, long startOffset, long length) {
        mNativeDict = openNative(path, startOffset, length,
                TYPED_LETTER_MULTIPLIER, FULL_WORD_SCORE_MULTIPLIER, MAX_WORD_LENGTH, MAX_WORDS);
        mNativeDict = openNative(path, startOffset, length, TYPED_LETTER_MULTIPLIER,
                FULL_WORD_SCORE_MULTIPLIER, MAX_WORD_LENGTH, MAX_WORDS, MAX_PREDICTIONS);
    }

    @Override
@@ -129,8 +130,8 @@ public class BinaryDictionary extends Dictionary {
            if (TextUtils.isEmpty(prevWord)) return null;
            int tmpCount = getBigramsNative(mNativeDict, prevWordCodePointArray,
                    prevWordCodePointArray.length, mInputCodes, composerSize,
                    mOutputChars, mOutputScores, MAX_WORD_LENGTH, MAX_BIGRAMS);
            count = Math.min(tmpCount, MAX_BIGRAMS);
                    mOutputChars, mOutputScores, MAX_WORD_LENGTH, MAX_PREDICTIONS);
            count = Math.min(tmpCount, MAX_PREDICTIONS);
        } else {
            final InputPointers ips = composer.getInputPointers();
            final int codesSize = isGesture ? ips.getPointerSize() : composerSize;
+4 −3
Original line number Diff line number Diff line
@@ -46,7 +46,8 @@ void releaseDictBuf(void* dictBuf, const size_t length, int fd);

static jlong latinime_BinaryDictionary_open(JNIEnv *env, jobject object,
        jstring sourceDir, jlong dictOffset, jlong dictSize,
        jint typedLetterMultiplier, jint fullWordMultiplier, jint maxWordLength, jint maxWords) {
        jint typedLetterMultiplier, jint fullWordMultiplier, jint maxWordLength, jint maxWords,
        jint maxPredictions) {
    PROF_OPEN;
    PROF_START(66);
    const char *sourceDirChars = env->GetStringUTFChars(sourceDir, 0);
@@ -119,7 +120,7 @@ static jlong latinime_BinaryDictionary_open(JNIEnv *env, jobject object,
#endif // USE_MMAP_FOR_DICTIONARY
    } else {
        dictionary = new Dictionary(dictBuf, dictSize, fd, adjust, typedLetterMultiplier,
                fullWordMultiplier, maxWordLength, maxWords);
                fullWordMultiplier, maxWordLength, maxWords, maxPredictions);
    }
    PROF_END(66);
    PROF_CLOSE;
@@ -258,7 +259,7 @@ void releaseDictBuf(void* dictBuf, const size_t length, int fd) {
}

static JNINativeMethod sMethods[] = {
    {"openNative", "(Ljava/lang/String;JJIIII)J", (void*)latinime_BinaryDictionary_open},
    {"openNative", "(Ljava/lang/String;JJIIIII)J", (void*)latinime_BinaryDictionary_open},
    {"closeNative", "(J)V", (void*)latinime_BinaryDictionary_close},
    {"getSuggestionsNative", "(JJ[I[I[I[I[IIIZ[IZ[C[I[I)I",
            (void*) latinime_BinaryDictionary_getSuggestions},
+2 −2
Original line number Diff line number Diff line
@@ -27,8 +27,8 @@

namespace latinime {

BigramDictionary::BigramDictionary(const unsigned char *dict, int maxWordLength)
        : DICT(dict), MAX_WORD_LENGTH(maxWordLength) {
BigramDictionary::BigramDictionary(const unsigned char *dict, int maxWordLength, int maxPredictions)
        : DICT(dict), MAX_WORD_LENGTH(maxWordLength), MAX_PREDICTIONS(maxPredictions) {
    if (DEBUG_DICT) {
        AKLOGI("BigramDictionary - constructor");
    }
+2 −1
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ namespace latinime {
class Dictionary;
class BigramDictionary {
 public:
    BigramDictionary(const unsigned char *dict, int maxWordLength);
    BigramDictionary(const unsigned char *dict, int maxWordLength, int maxPredictions);
    int getBigrams(const int32_t *word, int length, int *inputCodes, int codesSize,
            unsigned short *outWords, int *frequencies, int maxWordLength, int maxBigrams) const;
    int getBigramListPositionForWord(const int32_t *prevWord, const int prevWordLength,
@@ -49,6 +49,7 @@ class BigramDictionary {

    const unsigned char *DICT;
    const int MAX_WORD_LENGTH;
    const int MAX_PREDICTIONS;
    // TODO: Re-implement proximity correction for bigram correction
    static const int MAX_ALTERNATIVES = 1;
};
+2 −2
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ 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 maxWordLength, int maxWords, int maxPredictions)
    : mDict((unsigned char*) dict), mDictSize(dictSize),
      mMmapFd(mmapFd), mDictBufAdjust(dictBufAdjust) {
    if (DEBUG_DICT) {
@@ -43,7 +43,7 @@ Dictionary::Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust,
    const unsigned int options = BinaryFormat::getFlags(mDict);
    mUnigramDictionary = new UnigramDictionary(mDict + headerSize, typedLetterMultiplier,
            fullWordMultiplier, maxWordLength, maxWords, options);
    mBigramDictionary = new BigramDictionary(mDict + headerSize, maxWordLength);
    mBigramDictionary = new BigramDictionary(mDict + headerSize, maxWordLength, maxPredictions);
    mGestureDecoder = new GestureDecoderWrapper(maxWordLength, maxWords);
    mGestureDecoder->setDict(mUnigramDictionary, mBigramDictionary,
            mDict + headerSize /* dict root */, 0 /* root pos */);
Loading