Merge "A couple of cleanups. Remove unnecessary casts." into jb-mr1-dev
This commit is contained in:
commit
54035065c0
6 changed files with 28 additions and 29 deletions
|
@ -27,6 +27,7 @@
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#else // USE_MMAP_FOR_DICTIONARY
|
#else // USE_MMAP_FOR_DICTIONARY
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <cstdio> // for fopen() etc.
|
||||||
#endif // USE_MMAP_FOR_DICTIONARY
|
#endif // USE_MMAP_FOR_DICTIONARY
|
||||||
|
|
||||||
#include "binary_format.h"
|
#include "binary_format.h"
|
||||||
|
@ -40,7 +41,7 @@ namespace latinime {
|
||||||
|
|
||||||
class ProximityInfo;
|
class ProximityInfo;
|
||||||
|
|
||||||
static void releaseDictBuf(void *dictBuf, const size_t length, int fd);
|
static void releaseDictBuf(const void *dictBuf, const size_t length, const int fd);
|
||||||
|
|
||||||
static jlong latinime_BinaryDictionary_open(JNIEnv *env, jobject object,
|
static jlong latinime_BinaryDictionary_open(JNIEnv *env, jobject object,
|
||||||
jstring sourceDir, jlong dictOffset, jlong dictSize,
|
jstring sourceDir, jlong dictOffset, jlong dictSize,
|
||||||
|
@ -75,7 +76,7 @@ static jlong latinime_BinaryDictionary_open(JNIEnv *env, jobject object,
|
||||||
AKLOGE("DICT: Can't mmap dictionary. errno=%d", errno);
|
AKLOGE("DICT: Can't mmap dictionary. errno=%d", errno);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
dictBuf = reinterpret_cast<void *>(reinterpret_cast<char *>(dictBuf) + adjust);
|
dictBuf = static_cast<char *>(dictBuf) + adjust;
|
||||||
#else // USE_MMAP_FOR_DICTIONARY
|
#else // USE_MMAP_FOR_DICTIONARY
|
||||||
/* malloc version */
|
/* malloc version */
|
||||||
FILE *file = 0;
|
FILE *file = 0;
|
||||||
|
@ -111,10 +112,10 @@ static jlong latinime_BinaryDictionary_open(JNIEnv *env, jobject object,
|
||||||
}
|
}
|
||||||
Dictionary *dictionary = 0;
|
Dictionary *dictionary = 0;
|
||||||
if (BinaryFormat::UNKNOWN_FORMAT
|
if (BinaryFormat::UNKNOWN_FORMAT
|
||||||
== BinaryFormat::detectFormat(reinterpret_cast<uint8_t *>(dictBuf))) {
|
== BinaryFormat::detectFormat(static_cast<uint8_t *>(dictBuf))) {
|
||||||
AKLOGE("DICT: dictionary format is unknown, bad magic number");
|
AKLOGE("DICT: dictionary format is unknown, bad magic number");
|
||||||
#ifdef USE_MMAP_FOR_DICTIONARY
|
#ifdef USE_MMAP_FOR_DICTIONARY
|
||||||
releaseDictBuf(reinterpret_cast<char *>(dictBuf) - adjust, adjDictSize, fd);
|
releaseDictBuf(static_cast<const char *>(dictBuf) - adjust, adjDictSize, fd);
|
||||||
#else // USE_MMAP_FOR_DICTIONARY
|
#else // USE_MMAP_FOR_DICTIONARY
|
||||||
releaseDictBuf(dictBuf, 0, 0);
|
releaseDictBuf(dictBuf, 0, 0);
|
||||||
#endif // USE_MMAP_FOR_DICTIONARY
|
#endif // USE_MMAP_FOR_DICTIONARY
|
||||||
|
@ -249,12 +250,10 @@ static jint latinime_BinaryDictionary_editDistance(JNIEnv *env, jobject object,
|
||||||
static void latinime_BinaryDictionary_close(JNIEnv *env, jobject object, jlong dict) {
|
static void latinime_BinaryDictionary_close(JNIEnv *env, jobject object, jlong dict) {
|
||||||
Dictionary *dictionary = reinterpret_cast<Dictionary *>(dict);
|
Dictionary *dictionary = reinterpret_cast<Dictionary *>(dict);
|
||||||
if (!dictionary) return;
|
if (!dictionary) return;
|
||||||
void *dictBuf = dictionary->getDict();
|
const void *dictBuf = dictionary->getDict();
|
||||||
if (!dictBuf) return;
|
if (!dictBuf) return;
|
||||||
#ifdef USE_MMAP_FOR_DICTIONARY
|
#ifdef USE_MMAP_FOR_DICTIONARY
|
||||||
releaseDictBuf(
|
releaseDictBuf(static_cast<const char *>(dictBuf) - dictionary->getDictBufAdjust(),
|
||||||
reinterpret_cast<void *>(
|
|
||||||
reinterpret_cast<char *>(dictBuf) - dictionary->getDictBufAdjust()),
|
|
||||||
dictionary->getDictSize() + dictionary->getDictBufAdjust(), dictionary->getMmapFd());
|
dictionary->getDictSize() + dictionary->getDictBufAdjust(), dictionary->getMmapFd());
|
||||||
#else // USE_MMAP_FOR_DICTIONARY
|
#else // USE_MMAP_FOR_DICTIONARY
|
||||||
releaseDictBuf(dictBuf, 0, 0);
|
releaseDictBuf(dictBuf, 0, 0);
|
||||||
|
@ -262,9 +261,9 @@ static void latinime_BinaryDictionary_close(JNIEnv *env, jobject object, jlong d
|
||||||
delete dictionary;
|
delete dictionary;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void releaseDictBuf(void *dictBuf, const size_t length, int fd) {
|
static void releaseDictBuf(const void *dictBuf, const size_t length, const int fd) {
|
||||||
#ifdef USE_MMAP_FOR_DICTIONARY
|
#ifdef USE_MMAP_FOR_DICTIONARY
|
||||||
int ret = munmap(dictBuf, length);
|
int ret = munmap(const_cast<void *>(dictBuf), length);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
AKLOGE("DICT: Failure in munmap. ret=%d errno=%d", ret, errno);
|
AKLOGE("DICT: Failure in munmap. ret=%d errno=%d", ret, errno);
|
||||||
}
|
}
|
||||||
|
@ -273,7 +272,7 @@ static void releaseDictBuf(void *dictBuf, const size_t length, int fd) {
|
||||||
AKLOGE("DICT: Failure in close. ret=%d errno=%d", ret, errno);
|
AKLOGE("DICT: Failure in close. ret=%d errno=%d", ret, errno);
|
||||||
}
|
}
|
||||||
#else // USE_MMAP_FOR_DICTIONARY
|
#else // USE_MMAP_FOR_DICTIONARY
|
||||||
free(dictBuf);
|
free(const_cast<void *>(dictBuf));
|
||||||
#endif // USE_MMAP_FOR_DICTIONARY
|
#endif // USE_MMAP_FOR_DICTIONARY
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,11 +55,11 @@ class Dictionary {
|
||||||
|
|
||||||
int getFrequency(const int32_t *word, int length) const;
|
int getFrequency(const int32_t *word, int length) const;
|
||||||
bool isValidBigram(const int32_t *word1, int length1, const int32_t *word2, int length2) const;
|
bool isValidBigram(const int32_t *word1, int length1, const int32_t *word2, int length2) const;
|
||||||
void *getDict() const { // required to release dictionary buffer
|
const uint8_t *getDict() const { // required to release dictionary buffer
|
||||||
return reinterpret_cast<void *>(const_cast<unsigned char *>(mDict));
|
return mDict;
|
||||||
}
|
}
|
||||||
void *getOffsetDict() const {
|
const uint8_t *getOffsetDict() const {
|
||||||
return reinterpret_cast<void *>(const_cast<unsigned char *>(mOffsetDict));
|
return mOffsetDict;
|
||||||
}
|
}
|
||||||
int getDictSize() const { return mDictSize; }
|
int getDictSize() const { return mDictSize; }
|
||||||
int getMmapFd() const { return mMmapFd; }
|
int getMmapFd() const { return mMmapFd; }
|
||||||
|
@ -72,8 +72,8 @@ class Dictionary {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DISALLOW_IMPLICIT_CONSTRUCTORS(Dictionary);
|
DISALLOW_IMPLICIT_CONSTRUCTORS(Dictionary);
|
||||||
const unsigned char *mDict;
|
const uint8_t *mDict;
|
||||||
const unsigned char *mOffsetDict;
|
const uint8_t *mOffsetDict;
|
||||||
|
|
||||||
// Used only for the mmap version of dictionary loading, but we use these as dummy variables
|
// Used only for the mmap version of dictionary loading, but we use these as dummy variables
|
||||||
// also for the malloc version.
|
// also for the malloc version.
|
||||||
|
|
Loading…
Reference in a new issue