am a72e8f1e: [RF3] Cleanups
* commit 'a72e8f1ede3dc11fb60bd1346e6c7cb07c5d126e': [RF3] Cleanupsmain
commit
f0a7495f84
|
@ -121,7 +121,6 @@ public final class BinaryDictionary extends Dictionary {
|
|||
String[] attributeKeyStringArray, String[] attributeValueStringArray);
|
||||
private static native long openNative(String sourceDir, long dictOffset, long dictSize,
|
||||
boolean isUpdatable);
|
||||
private static native boolean hasValidContentsNative(long dict);
|
||||
private static native void flushNative(long dict, String filePath);
|
||||
private static native boolean needsToRunGCNative(long dict, boolean mindsBlockByGC);
|
||||
private static native void flushWithGCNative(long dict, String filePath);
|
||||
|
@ -243,10 +242,6 @@ public final class BinaryDictionary extends Dictionary {
|
|||
return mNativeDict != 0;
|
||||
}
|
||||
|
||||
public boolean hasValidContents() {
|
||||
return hasValidContentsNative(mNativeDict);
|
||||
}
|
||||
|
||||
public int getFormatVersion() {
|
||||
return getFormatVersionNative(mNativeDict);
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ public final class DictionaryFactory {
|
|||
final ReadOnlyBinaryDictionary readOnlyBinaryDictionary =
|
||||
new ReadOnlyBinaryDictionary(f.mFilename, f.mOffset, f.mLength,
|
||||
useFullEditDistance, locale, Dictionary.TYPE_MAIN);
|
||||
if (readOnlyBinaryDictionary.hasValidContents()) {
|
||||
if (readOnlyBinaryDictionary.isValidDictionary()) {
|
||||
dictList.add(readOnlyBinaryDictionary);
|
||||
} else {
|
||||
readOnlyBinaryDictionary.close();
|
||||
|
|
|
@ -63,7 +63,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
|||
*/
|
||||
protected static final int MAX_WORD_LENGTH = Constants.DICTIONARY_MAX_WORD_LENGTH;
|
||||
|
||||
private static final int DICTIONARY_FORMAT_VERSION = 4;
|
||||
private static final int DICTIONARY_FORMAT_VERSION = FormatSpec.VERSION4;
|
||||
|
||||
/**
|
||||
* A static map of update controllers, each of which records the time of accesses to a single
|
||||
|
@ -139,8 +139,8 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
|||
return formatVersion == 2;
|
||||
}
|
||||
|
||||
public boolean hasValidContents() {
|
||||
return mBinaryDictionary.hasValidContents();
|
||||
public boolean isValidDictionary() {
|
||||
return mBinaryDictionary.isValidDictionary();
|
||||
}
|
||||
|
||||
protected String getFileNameExtentionToOpenDict() {
|
||||
|
@ -563,8 +563,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
|||
loadDictionaryAsync();
|
||||
mDictionaryWriter.write(mFilename, getHeaderAttributeMap());
|
||||
} else {
|
||||
if (mBinaryDictionary == null || !mBinaryDictionary.isValidDictionary()
|
||||
|| !hasValidContents()
|
||||
if (mBinaryDictionary == null || !isValidDictionary()
|
||||
// TODO: remove the check below
|
||||
|| !matchesExpectedBinaryDictFormatVersionForThisType(
|
||||
mBinaryDictionary.getFormatVersion())) {
|
||||
|
@ -665,8 +664,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
|||
// load the shared dictionary.
|
||||
loadBinaryDictionary();
|
||||
}
|
||||
if (mBinaryDictionary != null && !(mBinaryDictionary.isValidDictionary()
|
||||
&& hasValidContents()
|
||||
if (mBinaryDictionary != null && !(isValidDictionary()
|
||||
// TODO: remove the check below
|
||||
&& matchesExpectedBinaryDictFormatVersionForThisType(
|
||||
mBinaryDictionary.getFormatVersion()))) {
|
||||
|
|
|
@ -44,15 +44,6 @@ public final class ReadOnlyBinaryDictionary extends Dictionary {
|
|||
locale, dictType, false /* isUpdatable */);
|
||||
}
|
||||
|
||||
public boolean hasValidContents() {
|
||||
mLock.readLock().lock();
|
||||
try {
|
||||
return mBinaryDictionary.hasValidContents();
|
||||
} finally {
|
||||
mLock.readLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isValidDictionary() {
|
||||
return mBinaryDictionary.isValidDictionary();
|
||||
}
|
||||
|
|
|
@ -204,8 +204,8 @@ public final class FormatSpec {
|
|||
static final int NOT_A_VERSION_NUMBER = -1;
|
||||
static final int FIRST_VERSION_WITH_DYNAMIC_UPDATE = 3;
|
||||
static final int FIRST_VERSION_WITH_TERMINAL_ID = 4;
|
||||
static final int VERSION3 = 3;
|
||||
static final int VERSION4 = 4;
|
||||
public static final int VERSION3 = 3;
|
||||
public static final int VERSION4 = 4;
|
||||
|
||||
// These options need to be the same numeric values as the one in the native reading code.
|
||||
static final int GERMAN_UMLAUT_PROCESSING_FLAG = 0x1;
|
||||
|
|
|
@ -161,7 +161,7 @@ public class Ver4DictDecoder extends AbstractDictDecoder {
|
|||
}
|
||||
final FileHeader header = super.readHeader(mDictBuffer);
|
||||
final int version = header.mFormatOptions.mVersion;
|
||||
if (version != 4) {
|
||||
if (version != FormatSpec.VERSION4) {
|
||||
throw new UnsupportedFormatException("File header has a wrong version : " + version);
|
||||
}
|
||||
return header;
|
||||
|
|
|
@ -86,7 +86,7 @@ static jlong latinime_BinaryDictionary_open(JNIEnv *env, jclass clazz, jstring s
|
|||
char sourceDirChars[sourceDirUtf8Length + 1];
|
||||
env->GetStringUTFRegion(sourceDir, 0, env->GetStringLength(sourceDir), sourceDirChars);
|
||||
sourceDirChars[sourceDirUtf8Length] = '\0';
|
||||
DictionaryStructureWithBufferPolicy::StructurePoilcyPtr dictionaryStructureWithBufferPolicy =
|
||||
DictionaryStructureWithBufferPolicy::StructurePolicyPtr dictionaryStructureWithBufferPolicy =
|
||||
DictionaryStructureWithBufferPolicyFactory::newDictionaryStructureWithBufferPolicy(
|
||||
sourceDirChars, static_cast<int>(dictOffset), static_cast<int>(dictSize),
|
||||
isUpdatable == JNI_TRUE);
|
||||
|
@ -135,14 +135,6 @@ static void latinime_BinaryDictionary_close(JNIEnv *env, jclass clazz, jlong dic
|
|||
delete dictionary;
|
||||
}
|
||||
|
||||
static bool latinime_BinaryDictionary_hasValidContents(JNIEnv *env, jclass clazz,
|
||||
jlong dict) {
|
||||
Dictionary *dictionary = reinterpret_cast<Dictionary *>(dict);
|
||||
if (!dictionary) return false;
|
||||
// TODO: check format version
|
||||
return true;
|
||||
}
|
||||
|
||||
static int latinime_BinaryDictionary_getFormatVersion(JNIEnv *env, jclass clazz, jlong dict) {
|
||||
Dictionary *dictionary = reinterpret_cast<Dictionary *>(dict);
|
||||
if (!dictionary) return 0;
|
||||
|
@ -466,11 +458,6 @@ static const JNINativeMethod sMethods[] = {
|
|||
const_cast<char *>("(J)V"),
|
||||
reinterpret_cast<void *>(latinime_BinaryDictionary_close)
|
||||
},
|
||||
{
|
||||
const_cast<char *>("hasValidContentsNative"),
|
||||
const_cast<char *>("(J)Z"),
|
||||
reinterpret_cast<void *>(latinime_BinaryDictionary_hasValidContents)
|
||||
},
|
||||
{
|
||||
const_cast<char *>("getFormatVersionNative"),
|
||||
const_cast<char *>("(J)I"),
|
||||
|
|
|
@ -34,7 +34,7 @@ namespace latinime {
|
|||
|
||||
const int Dictionary::HEADER_ATTRIBUTE_BUFFER_SIZE = 32;
|
||||
|
||||
Dictionary::Dictionary(JNIEnv *env, const DictionaryStructureWithBufferPolicy::StructurePoilcyPtr
|
||||
Dictionary::Dictionary(JNIEnv *env, const DictionaryStructureWithBufferPolicy::StructurePolicyPtr
|
||||
&dictionaryStructureWithBufferPolicy)
|
||||
: mDictionaryStructureWithBufferPolicy(dictionaryStructureWithBufferPolicy),
|
||||
mBigramDictionary(new BigramDictionary(mDictionaryStructureWithBufferPolicy.get())),
|
||||
|
|
|
@ -56,8 +56,8 @@ class Dictionary {
|
|||
static const int KIND_FLAG_POSSIBLY_OFFENSIVE = 0x80000000;
|
||||
static const int KIND_FLAG_EXACT_MATCH = 0x40000000;
|
||||
|
||||
Dictionary(JNIEnv *env, const DictionaryStructureWithBufferPolicy::StructurePoilcyPtr
|
||||
&dictionaryStructureWithBufferPoilcy);
|
||||
Dictionary(JNIEnv *env, const DictionaryStructureWithBufferPolicy::StructurePolicyPtr
|
||||
&dictionaryStructureWithBufferPolicy);
|
||||
|
||||
int getSuggestions(ProximityInfo *proximityInfo, DicTraverseSession *traverseSession,
|
||||
int *xcoordinates, int *ycoordinates, int *times, int *pointerIds, int *inputCodePoints,
|
||||
|
@ -109,7 +109,7 @@ class Dictionary {
|
|||
|
||||
static const int HEADER_ATTRIBUTE_BUFFER_SIZE;
|
||||
|
||||
const DictionaryStructureWithBufferPolicy::StructurePoilcyPtr
|
||||
const DictionaryStructureWithBufferPolicy::StructurePolicyPtr
|
||||
mDictionaryStructureWithBufferPolicy;
|
||||
const BigramDictionaryPtr mBigramDictionary;
|
||||
const SuggestInterfacePtr mGestureSuggest;
|
||||
|
|
|
@ -29,12 +29,12 @@ class DictionaryHeaderStructurePolicy;
|
|||
class DictionaryShortcutsStructurePolicy;
|
||||
|
||||
/*
|
||||
* This class abstracts structure of dictionaries.
|
||||
* This class abstracts the structure of dictionaries.
|
||||
* Implement this policy to support additional dictionaries.
|
||||
*/
|
||||
class DictionaryStructureWithBufferPolicy {
|
||||
public:
|
||||
typedef ExclusiveOwnershipPointer<DictionaryStructureWithBufferPolicy> StructurePoilcyPtr;
|
||||
typedef ExclusiveOwnershipPointer<DictionaryStructureWithBufferPolicy> StructurePolicyPtr;
|
||||
|
||||
virtual ~DictionaryStructureWithBufferPolicy() {}
|
||||
|
||||
|
|
|
@ -78,15 +78,18 @@ class HeaderPolicy : public DictionaryHeaderStructurePolicy {
|
|||
~HeaderPolicy() {}
|
||||
|
||||
virtual int getFormatVersionNumber() const {
|
||||
// Conceptually this converts the symbolic value we use in the code into the
|
||||
// hardcoded of the bytes in the file. But we want the constants to be the
|
||||
// same so we use them for both here.
|
||||
switch (mDictFormatVersion) {
|
||||
case FormatUtils::VERSION_2:
|
||||
return 2;
|
||||
return FormatUtils::VERSION_2;
|
||||
case FormatUtils::VERSION_3:
|
||||
return 3;
|
||||
return FormatUtils::VERSION_3;
|
||||
case FormatUtils::VERSION_4:
|
||||
return 4;
|
||||
return FormatUtils::VERSION_4;
|
||||
default:
|
||||
return 0;
|
||||
return FormatUtils::UNKNOWN_VERSION;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
|
||||
namespace latinime {
|
||||
|
||||
/* static */ DictionaryStructureWithBufferPolicy::StructurePoilcyPtr
|
||||
/* static */ DictionaryStructureWithBufferPolicy::StructurePolicyPtr
|
||||
DictionaryStructureWithBufferPolicyFactory
|
||||
::newDictionaryStructureWithBufferPolicy(const char *const path,
|
||||
const int bufOffset, const int size, const bool isUpdatable) {
|
||||
|
@ -37,12 +37,12 @@ namespace latinime {
|
|||
MmappedBuffer::MmappedBufferPtr mmappedBuffer = MmappedBuffer::openBuffer(path, bufOffset, size,
|
||||
isUpdatable);
|
||||
if (!mmappedBuffer.get()) {
|
||||
return DictionaryStructureWithBufferPolicy::StructurePoilcyPtr(0);
|
||||
return DictionaryStructureWithBufferPolicy::StructurePolicyPtr(0);
|
||||
}
|
||||
switch (FormatUtils::detectFormatVersion(mmappedBuffer.get()->getBuffer(),
|
||||
mmappedBuffer.get()->getBufferSize())) {
|
||||
case FormatUtils::VERSION_2:
|
||||
return DictionaryStructureWithBufferPolicy::StructurePoilcyPtr(
|
||||
return DictionaryStructureWithBufferPolicy::StructurePolicyPtr(
|
||||
new PatriciaTriePolicy(mmappedBuffer));
|
||||
case FormatUtils::VERSION_4: {
|
||||
const int dictDirPathBufSize = strlen(path) + 1 /* terminator */;
|
||||
|
@ -50,22 +50,22 @@ namespace latinime {
|
|||
if (!FileUtils::getFilePathWithoutSuffix(path, Ver4DictConstants::TRIE_FILE_EXTENSION,
|
||||
dictDirPathBufSize, dictDirPath)) {
|
||||
// Dictionary file name is not valid as a version 4 dictionary.
|
||||
return DictionaryStructureWithBufferPolicy::StructurePoilcyPtr(0);
|
||||
return DictionaryStructureWithBufferPolicy::StructurePolicyPtr(0);
|
||||
}
|
||||
const Ver4DictBuffers::Ver4DictBuffersPtr dictBuffers =
|
||||
Ver4DictBuffers::openVer4DictBuffers(dictDirPath, mmappedBuffer);
|
||||
if (!dictBuffers.get()->isValid()) {
|
||||
AKLOGE("DICT: The dictionary doesn't satisfy ver4 format requirements.");
|
||||
ASSERT(false);
|
||||
return DictionaryStructureWithBufferPolicy::StructurePoilcyPtr(0);
|
||||
return DictionaryStructureWithBufferPolicy::StructurePolicyPtr(0);
|
||||
}
|
||||
return DictionaryStructureWithBufferPolicy::StructurePoilcyPtr(
|
||||
return DictionaryStructureWithBufferPolicy::StructurePolicyPtr(
|
||||
new Ver4PatriciaTriePolicy(dictBuffers));
|
||||
}
|
||||
default:
|
||||
AKLOGE("DICT: dictionary format is unknown, bad magic number");
|
||||
ASSERT(false);
|
||||
return DictionaryStructureWithBufferPolicy::StructurePoilcyPtr(0);
|
||||
return DictionaryStructureWithBufferPolicy::StructurePolicyPtr(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace latinime {
|
|||
|
||||
class DictionaryStructureWithBufferPolicyFactory {
|
||||
public:
|
||||
static DictionaryStructureWithBufferPolicy::StructurePoilcyPtr
|
||||
static DictionaryStructureWithBufferPolicy::StructurePolicyPtr
|
||||
newDictionaryStructureWithBufferPolicy(const char *const path, const int bufOffset,
|
||||
const int size, const bool isUpdatable);
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ const char *const DictFileWritingUtils::TEMP_FILE_SUFFIX_FOR_WRITING_DICT_FILE =
|
|||
const int dictVersion, const HeaderReadWriteUtils::AttributeMap *const attributeMap) {
|
||||
TimeKeeper::setCurrentTime();
|
||||
switch (dictVersion) {
|
||||
case 4:
|
||||
case FormatUtils::VERSION_4:
|
||||
return createEmptyV4DictFile(filePath, attributeMap);
|
||||
default:
|
||||
AKLOGE("Cannot create dictionary %s because format version %d is not supported.",
|
||||
|
|
|
@ -41,11 +41,14 @@ const int FormatUtils::DICTIONARY_MINIMUM_SIZE = 12;
|
|||
// Dictionary format version number (2 bytes)
|
||||
// Options (2 bytes)
|
||||
// Header size (4 bytes) : integer, big endian
|
||||
if (ByteArrayUtils::readUint16(dict, 4) == 2) {
|
||||
// Conceptually this converts the hardcoded value of the bytes in the file into
|
||||
// the symbolic value we use in the code. But we want the constants to be the
|
||||
// same so we use them for both here.
|
||||
if (ByteArrayUtils::readUint16(dict, 4) == VERSION_2) {
|
||||
return VERSION_2;
|
||||
} else if (ByteArrayUtils::readUint16(dict, 4) == 3) {
|
||||
} else if (ByteArrayUtils::readUint16(dict, 4) == VERSION_3) {
|
||||
return VERSION_3;
|
||||
} else if (ByteArrayUtils::readUint16(dict, 4) == 4) {
|
||||
} else if (ByteArrayUtils::readUint16(dict, 4) == VERSION_4) {
|
||||
return VERSION_4;
|
||||
} else {
|
||||
return UNKNOWN_VERSION;
|
||||
|
|
|
@ -29,10 +29,10 @@ namespace latinime {
|
|||
class FormatUtils {
|
||||
public:
|
||||
enum FORMAT_VERSION {
|
||||
VERSION_2,
|
||||
VERSION_3,
|
||||
VERSION_4,
|
||||
UNKNOWN_VERSION
|
||||
VERSION_2 = 2,
|
||||
VERSION_3 = 3,
|
||||
VERSION_4 = 4,
|
||||
UNKNOWN_VERSION = -1
|
||||
};
|
||||
|
||||
// 32 bit magic number is stored at the beginning of the dictionary header to reject
|
||||
|
|
Loading…
Reference in New Issue