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

Commit b118a9d7 authored by Keisuke Kuroyanagi's avatar Keisuke Kuroyanagi Committed by Android (Google) Code Review
Browse files

Merge "Change cache capacity depending on the dictionary size."

parents 695a5a39 4c276785
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ public final class BinaryDictionary extends Dictionary {

    private long mNativeDict;
    private final Locale mLocale;
    private final long mDictSize;
    private final int[] mInputCodePoints = new int[MAX_WORD_LENGTH];
    private final int[] mOutputCodePoints = new int[MAX_WORD_LENGTH * MAX_RESULTS];
    private final int[] mSpaceIndices = new int[MAX_RESULTS];
@@ -62,7 +63,7 @@ public final class BinaryDictionary extends Dictionary {
            if (traverseSession == null) {
                traverseSession = mDicTraverseSessions.get(traverseSessionId);
                if (traverseSession == null) {
                    traverseSession = new DicTraverseSession(mLocale, mNativeDict);
                    traverseSession = new DicTraverseSession(mLocale, mNativeDict, mDictSize);
                    mDicTraverseSessions.put(traverseSessionId, traverseSession);
                }
            }
@@ -85,6 +86,7 @@ public final class BinaryDictionary extends Dictionary {
            final boolean isUpdatable) {
        super(dictType);
        mLocale = locale;
        mDictSize = length;
        mNativeSuggestOptions.setUseFullEditDistance(useFullEditDistance);
        loadDictionary(filename, offset, length, isUpdatable);
    }
+5 −5
Original line number Diff line number Diff line
@@ -25,16 +25,16 @@ public final class DicTraverseSession {
        JniUtils.loadNativeLibrary();
    }

    private static native long setDicTraverseSessionNative(String locale);
    private static native long setDicTraverseSessionNative(String locale, long dictSize);
    private static native void initDicTraverseSessionNative(long nativeDicTraverseSession,
            long dictionary, int[] previousWord, int previousWordLength);
    private static native void releaseDicTraverseSessionNative(long nativeDicTraverseSession);

    private long mNativeDicTraverseSession;

    public DicTraverseSession(Locale locale, long dictionary) {
    public DicTraverseSession(Locale locale, long dictionary, long dictSize) {
        mNativeDicTraverseSession = createNativeDicTraverseSession(
                locale != null ? locale.toString() : "");
                locale != null ? locale.toString() : "", dictSize);
        initSession(dictionary);
    }

@@ -51,8 +51,8 @@ public final class DicTraverseSession {
                mNativeDicTraverseSession, dictionary, previousWord, previousWordLength);
    }

    private final long createNativeDicTraverseSession(String locale) {
        return setDicTraverseSessionNative(locale);
    private final long createNativeDicTraverseSession(String locale, long dictSize) {
        return setDicTraverseSessionNative(locale, dictSize);
    }

    private void closeInternal() {
+4 −3
Original line number Diff line number Diff line
@@ -25,8 +25,9 @@

namespace latinime {
class Dictionary;
static jlong latinime_setDicTraverseSession(JNIEnv *env, jclass clazz, jstring localeJStr) {
    void *traverseSession = DicTraverseSession::getSessionInstance(env, localeJStr);
static jlong latinime_setDicTraverseSession(JNIEnv *env, jclass clazz, jstring localeJStr,
        jlong dictSize) {
    void *traverseSession = DicTraverseSession::getSessionInstance(env, localeJStr, dictSize);
    return reinterpret_cast<jlong>(traverseSession);
}

@@ -53,7 +54,7 @@ static void latinime_releaseDicTraverseSession(JNIEnv *env, jclass clazz, jlong
static const JNINativeMethod sMethods[] = {
    {
        const_cast<char *>("setDicTraverseSessionNative"),
        const_cast<char *>("(Ljava/lang/String;)J"),
        const_cast<char *>("(Ljava/lang/String;J)J"),
        reinterpret_cast<void *>(latinime_setDicTraverseSession)
    },
    {
+0 −2
Original line number Diff line number Diff line
@@ -32,8 +32,6 @@
#define MAX_WORD_LENGTH 48
// Must be equal to BinaryDictionary.MAX_RESULTS in Java
#define MAX_RESULTS 18
// The biggest value among MAX_CACHE_DIC_NODE_SIZE, MAX_CACHE_DIC_NODE_SIZE_FOR_SINGLE_POINT, ...
#define MAX_DIC_NODE_PRIORITY_QUEUE_CAPACITY 310
// Must be equal to ProximityInfo.MAX_PROXIMITY_CHARS_SIZE in Java
#define MAX_PROXIMITY_CHARS_SIZE 16
#define ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE 2
+5 −0
Original line number Diff line number Diff line
@@ -23,6 +23,11 @@

namespace latinime {

// The biggest value among MAX_CACHE_DIC_NODE_SIZE, MAX_CACHE_DIC_NODE_SIZE_FOR_SINGLE_POINT, ...
const int DicNodesCache::LARGE_PRIORITY_QUEUE_CAPACITY = 310;
// Capacity for reducing memory footprint.
const int DicNodesCache::SMALL_PRIORITY_QUEUE_CAPACITY = 100;

/**
 * Truncates all of the dicNodes so that they start at the given commit point.
 * Only called for multi-word typing input.
Loading