Cleanup casts.

Change-Id: I3bf33ca407cc3bee9f5c4c6f929cdb1421b92c50
This commit is contained in:
Ken Wakasa 2012-08-14 18:54:13 +09:00
parent 54035065c0
commit 267030dd82
6 changed files with 19 additions and 22 deletions

View file

@ -230,8 +230,8 @@ static jfloat latinime_BinaryDictionary_calcNormalizedScore(JNIEnv *env, jobject
env->GetCharArrayRegion(before, 0, beforeLength, beforeChars); env->GetCharArrayRegion(before, 0, beforeLength, beforeChars);
env->GetCharArrayRegion(after, 0, afterLength, afterChars); env->GetCharArrayRegion(after, 0, afterLength, afterChars);
return Correction::RankingAlgorithm::calcNormalizedScore( return Correction::RankingAlgorithm::calcNormalizedScore(
reinterpret_cast<unsigned short *>(beforeChars), beforeLength, static_cast<unsigned short *>(beforeChars), beforeLength,
reinterpret_cast<unsigned short *>(afterChars), afterLength, score); static_cast<unsigned short *>(afterChars), afterLength, score);
} }
static jint latinime_BinaryDictionary_editDistance(JNIEnv *env, jobject object, static jint latinime_BinaryDictionary_editDistance(JNIEnv *env, jobject object,
@ -243,8 +243,8 @@ static jint latinime_BinaryDictionary_editDistance(JNIEnv *env, jobject object,
env->GetCharArrayRegion(before, 0, beforeLength, beforeChars); env->GetCharArrayRegion(before, 0, beforeLength, beforeChars);
env->GetCharArrayRegion(after, 0, afterLength, afterChars); env->GetCharArrayRegion(after, 0, afterLength, afterChars);
return Correction::RankingAlgorithm::editDistance( return Correction::RankingAlgorithm::editDistance(
reinterpret_cast<unsigned short *>(beforeChars), beforeLength, static_cast<unsigned short *>(beforeChars), beforeLength,
reinterpret_cast<unsigned short *>(afterChars), afterLength); static_cast<unsigned short *>(afterChars), afterLength);
} }
static void latinime_BinaryDictionary_close(JNIEnv *env, jobject object, jlong dict) { static void latinime_BinaryDictionary_close(JNIEnv *env, jobject object, jlong dict) {

View file

@ -60,16 +60,15 @@ bool BigramDictionary::addWordBigram(unsigned short *word, int length, int frequ
AKLOGI("Bigram: InsertAt -> %d MAX_PREDICTIONS: %d", insertAt, MAX_PREDICTIONS); AKLOGI("Bigram: InsertAt -> %d MAX_PREDICTIONS: %d", insertAt, MAX_PREDICTIONS);
} }
if (insertAt < MAX_PREDICTIONS) { if (insertAt < MAX_PREDICTIONS) {
memmove(reinterpret_cast<char *>(bigramFreq) + (insertAt + 1) * sizeof(bigramFreq[0]), memmove(bigramFreq + (insertAt + 1),
reinterpret_cast<char *>(bigramFreq) + insertAt * sizeof(bigramFreq[0]), bigramFreq + insertAt,
(MAX_PREDICTIONS - insertAt - 1) * sizeof(bigramFreq[0])); (MAX_PREDICTIONS - insertAt - 1) * sizeof(bigramFreq[0]));
bigramFreq[insertAt] = frequency; bigramFreq[insertAt] = frequency;
outputTypes[insertAt] = Dictionary::KIND_PREDICTION; outputTypes[insertAt] = Dictionary::KIND_PREDICTION;
memmove(reinterpret_cast<char *>(bigramChars) memmove(bigramChars + (insertAt + 1) * MAX_WORD_LENGTH,
+ (insertAt + 1) * MAX_WORD_LENGTH * sizeof(short), bigramChars + insertAt * MAX_WORD_LENGTH,
reinterpret_cast<char *>(bigramChars) + insertAt * MAX_WORD_LENGTH * sizeof(short), (MAX_PREDICTIONS - insertAt - 1) * sizeof(bigramChars[0]) * MAX_WORD_LENGTH);
(MAX_PREDICTIONS - insertAt - 1) * sizeof(short) * MAX_WORD_LENGTH); unsigned short *dest = bigramChars + insertAt * MAX_WORD_LENGTH;
unsigned short *dest = bigramChars + (insertAt ) * MAX_WORD_LENGTH;
while (length--) { while (length--) {
*dest++ = *word++; *dest++ = *word++;
} }

View file

@ -885,14 +885,13 @@ static const struct LatinCapitalSmallPair SORTED_CHAR_MAP[] = {
}; };
static int compare_pair_capital(const void *a, const void *b) { static int compare_pair_capital(const void *a, const void *b) {
return static_cast<int>(*reinterpret_cast<const unsigned short *>(a)) return static_cast<int>(*static_cast<const unsigned short *>(a))
- static_cast<int>( - static_cast<int>((static_cast<const struct LatinCapitalSmallPair *>(b))->capital);
(reinterpret_cast<const struct LatinCapitalSmallPair *>(b))->capital);
} }
unsigned short latin_tolower(unsigned short c) { unsigned short latin_tolower(unsigned short c) {
struct LatinCapitalSmallPair *p = struct LatinCapitalSmallPair *p =
reinterpret_cast<struct LatinCapitalSmallPair *>(bsearch(&c, SORTED_CHAR_MAP, static_cast<struct LatinCapitalSmallPair *>(bsearch(&c, SORTED_CHAR_MAP,
sizeof(SORTED_CHAR_MAP) / sizeof(SORTED_CHAR_MAP[0]), sizeof(SORTED_CHAR_MAP) / sizeof(SORTED_CHAR_MAP[0]),
sizeof(SORTED_CHAR_MAP[0]), sizeof(SORTED_CHAR_MAP[0]),
compare_pair_capital)); compare_pair_capital));

View file

@ -58,7 +58,7 @@ static inline void LOGI_S16_PLUS(unsigned short *string, const unsigned int leng
} }
static inline void printDebug(const char *tag, int *codes, int codesSize, int MAX_PROXIMITY_CHARS) { static inline void printDebug(const char *tag, int *codes, int codesSize, int MAX_PROXIMITY_CHARS) {
unsigned char *buf = reinterpret_cast<unsigned char *>(malloc((1 + codesSize) * sizeof(*buf))); unsigned char *buf = static_cast<unsigned char *>(malloc((1 + codesSize) * sizeof(*buf)));
buf[codesSize] = 0; buf[codesSize] = 0;
while (--codesSize >= 0) { while (--codesSize >= 0) {

View file

@ -32,8 +32,8 @@ namespace latinime {
Dictionary::Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust, Dictionary::Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust,
int typedLetterMultiplier, int fullWordMultiplier, int typedLetterMultiplier, int fullWordMultiplier,
int maxWordLength, int maxWords, int maxPredictions) int maxWordLength, int maxWords, int maxPredictions)
: mDict(reinterpret_cast<unsigned char *>(dict)), : mDict(static_cast<unsigned char *>(dict)),
mOffsetDict((reinterpret_cast<unsigned char *>(dict)) + BinaryFormat::getHeaderSize(mDict)), mOffsetDict((static_cast<unsigned char *>(dict)) + BinaryFormat::getHeaderSize(mDict)),
mDictSize(dictSize), mMmapFd(mmapFd), mDictBufAdjust(dictBufAdjust) { mDictSize(dictSize), mMmapFd(mmapFd), mDictBufAdjust(dictBufAdjust) {
if (DEBUG_DICT) { if (DEBUG_DICT) {
if (MAX_WORD_LENGTH_INTERNAL < maxWordLength) { if (MAX_WORD_LENGTH_INTERNAL < maxWordLength) {

View file

@ -140,13 +140,12 @@ class WordsPriorityQueue {
continue; continue;
} }
const unsigned int wordLength = sw->mWordLength; const unsigned int wordLength = sw->mWordLength;
char *targetAddress = reinterpret_cast<char *>(outputChars) unsigned short *targetAddress = outputChars + i * MAX_WORD_LENGTH;
+ i * MAX_WORD_LENGTH * sizeof(short);
frequencies[i] = sw->mScore; frequencies[i] = sw->mScore;
outputTypes[i] = sw->mType; outputTypes[i] = sw->mType;
memcpy(targetAddress, sw->mWord, (wordLength) * sizeof(short)); memcpy(targetAddress, sw->mWord, wordLength * sizeof(unsigned short));
if (wordLength < MAX_WORD_LENGTH) { if (wordLength < MAX_WORD_LENGTH) {
reinterpret_cast<unsigned short *>(targetAddress)[wordLength] = 0; targetAddress[wordLength] = 0;
} }
sw->mUsed = false; sw->mUsed = false;
} }