am 54035065: Merge "A couple of cleanups. Remove unnecessary casts." into jb-mr1-dev

* commit '54035065c0ba516af408b1a3e12e12b1483ed61a':
  A couple of cleanups.  Remove unnecessary casts.
This commit is contained in:
Ken Wakasa 2012-08-14 02:20:11 -07:00 committed by Android Git Automerger
commit 6c2c1a04f1
6 changed files with 28 additions and 29 deletions

View file

@ -37,7 +37,7 @@ static jlong latinime_Keyboard_setProximityInfo(JNIEnv *env, jobject object,
} }
static void latinime_Keyboard_release(JNIEnv *env, jobject object, jlong proximityInfo) { static void latinime_Keyboard_release(JNIEnv *env, jobject object, jlong proximityInfo) {
ProximityInfo *pi = reinterpret_cast<ProximityInfo*>(proximityInfo); ProximityInfo *pi = reinterpret_cast<ProximityInfo *>(proximityInfo);
delete pi; delete pi;
} }

View file

@ -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
@ -134,10 +135,10 @@ static int latinime_BinaryDictionary_getSuggestions(JNIEnv *env, jobject object,
jintArray prevWordCodePointsForBigrams, jboolean useFullEditDistance, jintArray prevWordCodePointsForBigrams, jboolean useFullEditDistance,
jcharArray outputCharsArray, jintArray scoresArray, jintArray spaceIndicesArray, jcharArray outputCharsArray, jintArray scoresArray, jintArray spaceIndicesArray,
jintArray outputTypesArray) { jintArray outputTypesArray) {
Dictionary *dictionary = reinterpret_cast<Dictionary*>(dict); Dictionary *dictionary = reinterpret_cast<Dictionary *>(dict);
if (!dictionary) return 0; if (!dictionary) return 0;
ProximityInfo *pInfo = reinterpret_cast<ProximityInfo*>(proximityInfo); ProximityInfo *pInfo = reinterpret_cast<ProximityInfo *>(proximityInfo);
void *traverseSession = reinterpret_cast<void*>(dicTraverseSession); void *traverseSession = reinterpret_cast<void *>(dicTraverseSession);
// Input values // Input values
int xCoordinates[arraySize]; int xCoordinates[arraySize];
@ -199,7 +200,7 @@ static int latinime_BinaryDictionary_getSuggestions(JNIEnv *env, jobject object,
static jint latinime_BinaryDictionary_getFrequency(JNIEnv *env, jobject object, jlong dict, static jint latinime_BinaryDictionary_getFrequency(JNIEnv *env, jobject object, jlong dict,
jintArray wordArray) { jintArray wordArray) {
Dictionary *dictionary = reinterpret_cast<Dictionary*>(dict); Dictionary *dictionary = reinterpret_cast<Dictionary *>(dict);
if (!dictionary) return 0; if (!dictionary) return 0;
const jsize codePointLength = env->GetArrayLength(wordArray); const jsize codePointLength = env->GetArrayLength(wordArray);
int codePoints[codePointLength]; int codePoints[codePointLength];
@ -209,7 +210,7 @@ static jint latinime_BinaryDictionary_getFrequency(JNIEnv *env, jobject object,
static jboolean latinime_BinaryDictionary_isValidBigram(JNIEnv *env, jobject object, jlong dict, static jboolean latinime_BinaryDictionary_isValidBigram(JNIEnv *env, jobject object, jlong dict,
jintArray wordArray1, jintArray wordArray2) { jintArray wordArray1, jintArray wordArray2) {
Dictionary *dictionary = reinterpret_cast<Dictionary*>(dict); Dictionary *dictionary = reinterpret_cast<Dictionary *>(dict);
if (!dictionary) return (jboolean) false; if (!dictionary) return (jboolean) false;
const jsize codePointLength1 = env->GetArrayLength(wordArray1); const jsize codePointLength1 = env->GetArrayLength(wordArray1);
const jsize codePointLength2 = env->GetArrayLength(wordArray2); const jsize codePointLength2 = env->GetArrayLength(wordArray2);
@ -247,14 +248,12 @@ 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
} }

View file

@ -30,8 +30,8 @@ static jlong latinime_setDicTraverseSession(JNIEnv *env, jobject object, jstring
static void latinime_initDicTraverseSession(JNIEnv *env, jobject object, jlong traverseSession, static void latinime_initDicTraverseSession(JNIEnv *env, jobject object, jlong traverseSession,
jlong dictionary, jintArray previousWord, jint previousWordLength) { jlong dictionary, jintArray previousWord, jint previousWordLength) {
void *ts = reinterpret_cast<void*>(traverseSession); void *ts = reinterpret_cast<void *>(traverseSession);
Dictionary *dict = reinterpret_cast<Dictionary*>(dictionary); Dictionary *dict = reinterpret_cast<Dictionary *>(dictionary);
if (!previousWord) { if (!previousWord) {
DicTraverseWrapper::initDicTraverseSession(ts, dict, 0, 0); DicTraverseWrapper::initDicTraverseSession(ts, dict, 0, 0);
return; return;
@ -42,7 +42,7 @@ static void latinime_initDicTraverseSession(JNIEnv *env, jobject object, jlong t
} }
static void latinime_releaseDicTraverseSession(JNIEnv *env, jobject object, jlong traverseSession) { static void latinime_releaseDicTraverseSession(JNIEnv *env, jobject object, jlong traverseSession) {
void *ts = reinterpret_cast<void*>(traverseSession); void *ts = reinterpret_cast<void *>(traverseSession);
DicTraverseWrapper::releaseDicTraverseSession(ts); DicTraverseWrapper::releaseDicTraverseSession(ts);
} }

View file

@ -34,7 +34,7 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved) {
JNIEnv *env = 0; JNIEnv *env = 0;
jint result = -1; jint result = -1;
if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) { if (vm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_6) != JNI_OK) {
AKLOGE("ERROR: GetEnv failed"); AKLOGE("ERROR: GetEnv failed");
goto bail; goto bail;
} }

View file

@ -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.

View file

@ -223,7 +223,7 @@ class WordsPriorityQueue {
before, beforeLength, word, wordLength, score); before, beforeLength, word, wordLength, score);
} }
typedef std::priority_queue<SuggestedWord*, std::vector<SuggestedWord*>, typedef std::priority_queue<SuggestedWord *, std::vector<SuggestedWord *>,
wordComparator> Suggestions; wordComparator> Suggestions;
Suggestions mSuggestions; Suggestions mSuggestions;
const unsigned int MAX_WORDS; const unsigned int MAX_WORDS;