Adjust compiler warning options with the offdevice Makefile

Make use of AK_FORCE_INLINE for -Winline and better performance

Change-Id: If0016e2ef61c1fe007c83bb1a5133a6b6bde568e
main
Ken Wakasa 2012-11-03 02:50:47 +09:00
parent 19d844c7a7
commit 6e66349ed1
13 changed files with 52 additions and 38 deletions

View File

@ -28,7 +28,9 @@ LATIN_IME_SRC_FULLPATH_DIR := $(LOCAL_PATH)/$(LATIN_IME_SRC_DIR)
LOCAL_C_INCLUDES += $(LATIN_IME_SRC_FULLPATH_DIR) $(LATIN_IME_SRC_FULLPATH_DIR)/gesture LOCAL_C_INCLUDES += $(LATIN_IME_SRC_FULLPATH_DIR) $(LATIN_IME_SRC_FULLPATH_DIR)/gesture
LOCAL_CFLAGS += -Werror -Wall -Wextra -Weffc++ -Wno-system-headers LOCAL_CFLAGS += -Werror -Wall -Wextra -Weffc++ -Wformat=2 -Wcast-qual -Wcast-align \
-Wwrite-strings -Wfloat-equal -Wpointer-arith -Winit-self -Wredundant-decls \
-Winline -Wno-system-headers
# To suppress compiler warnings for unused variables/functions used for debug features etc. # To suppress compiler warnings for unused variables/functions used for debug features etc.
LOCAL_CFLAGS += -Wno-unused-parameter -Wno-unused-function LOCAL_CFLAGS += -Wno-unused-parameter -Wno-unused-function

View File

@ -39,7 +39,7 @@ class AdditionalProximityChars {
static const int EN_US_ADDITIONAL_U_SIZE = 4; static const int EN_US_ADDITIONAL_U_SIZE = 4;
static const int32_t EN_US_ADDITIONAL_U[]; static const int32_t EN_US_ADDITIONAL_U[];
static bool isEnLocale(const char *localeStr) { AK_FORCE_INLINE static bool isEnLocale(const char *localeStr) {
const size_t LOCALE_EN_US_SIZE = strlen(LOCALE_EN_US); const size_t LOCALE_EN_US_SIZE = strlen(LOCALE_EN_US);
return localeStr && strlen(localeStr) >= LOCALE_EN_US_SIZE return localeStr && strlen(localeStr) >= LOCALE_EN_US_SIZE
&& strncmp(localeStr, LOCALE_EN_US, LOCALE_EN_US_SIZE) == 0; && strncmp(localeStr, LOCALE_EN_US, LOCALE_EN_US_SIZE) == 0;

View File

@ -123,7 +123,7 @@ class BinaryFormat {
static int skipAllAttributes(const uint8_t *const dict, const uint8_t flags, const int pos); static int skipAllAttributes(const uint8_t *const dict, const uint8_t flags, const int pos);
}; };
inline int BinaryFormat::detectFormat(const uint8_t *const dict) { AK_FORCE_INLINE int BinaryFormat::detectFormat(const uint8_t *const dict) {
// The magic number is stored big-endian. // The magic number is stored big-endian.
const uint32_t magicNumber = (dict[0] << 24) + (dict[1] << 16) + (dict[2] << 8) + dict[3]; const uint32_t magicNumber = (dict[0] << 24) + (dict[1] << 16) + (dict[2] << 8) + dict[3];
switch (magicNumber) { switch (magicNumber) {
@ -166,7 +166,8 @@ inline unsigned int BinaryFormat::getHeaderSize(const uint8_t *const dict) {
} }
} }
inline int BinaryFormat::getGroupCountAndForwardPointer(const uint8_t *const dict, int *pos) { AK_FORCE_INLINE int BinaryFormat::getGroupCountAndForwardPointer(const uint8_t *const dict,
int *pos) {
const int msb = dict[(*pos)++]; const int msb = dict[(*pos)++];
if (msb < 0x80) return msb; if (msb < 0x80) return msb;
return ((msb & 0x7F) << 8) | dict[(*pos)++]; return ((msb & 0x7F) << 8) | dict[(*pos)++];
@ -176,7 +177,8 @@ inline uint8_t BinaryFormat::getFlagsAndForwardPointer(const uint8_t *const dict
return dict[(*pos)++]; return dict[(*pos)++];
} }
inline int BinaryFormat::getCodePointAndForwardPointer(const uint8_t *const dict, int *pos) { AK_FORCE_INLINE int BinaryFormat::getCodePointAndForwardPointer(const uint8_t *const dict,
int *pos) {
const int origin = *pos; const int origin = *pos;
const int codePoint = dict[origin]; const int codePoint = dict[origin];
if (codePoint < MINIMAL_ONE_BYTE_CHARACTER_VALUE) { if (codePoint < MINIMAL_ONE_BYTE_CHARACTER_VALUE) {
@ -200,7 +202,7 @@ inline int BinaryFormat::readFrequencyWithoutMovingPointer(const uint8_t *const
return dict[pos]; return dict[pos];
} }
inline int BinaryFormat::skipOtherCharacters(const uint8_t *const dict, const int pos) { AK_FORCE_INLINE int BinaryFormat::skipOtherCharacters(const uint8_t *const dict, const int pos) {
int currentPos = pos; int currentPos = pos;
int character = dict[currentPos++]; int character = dict[currentPos++];
while (CHARACTER_ARRAY_TERMINATOR != character) { while (CHARACTER_ARRAY_TERMINATOR != character) {
@ -226,7 +228,7 @@ static inline int attributeAddressSize(const uint8_t flags) {
*/ */
} }
static inline int skipExistingBigrams(const uint8_t *const dict, const int pos) { static AK_FORCE_INLINE int skipExistingBigrams(const uint8_t *const dict, const int pos) {
int currentPos = pos; int currentPos = pos;
uint8_t flags = BinaryFormat::getFlagsAndForwardPointer(dict, &currentPos); uint8_t flags = BinaryFormat::getFlagsAndForwardPointer(dict, &currentPos);
while (flags & BinaryFormat::FLAG_ATTRIBUTE_HAS_NEXT) { while (flags & BinaryFormat::FLAG_ATTRIBUTE_HAS_NEXT) {
@ -255,7 +257,7 @@ inline int BinaryFormat::skipFrequency(const uint8_t flags, const int pos) {
return FLAG_IS_TERMINAL & flags ? pos + 1 : pos; return FLAG_IS_TERMINAL & flags ? pos + 1 : pos;
} }
inline int BinaryFormat::skipShortcuts(const uint8_t *const dict, const uint8_t flags, AK_FORCE_INLINE int BinaryFormat::skipShortcuts(const uint8_t *const dict, const uint8_t flags,
const int pos) { const int pos) {
if (FLAG_HAS_SHORTCUT_TARGETS & flags) { if (FLAG_HAS_SHORTCUT_TARGETS & flags) {
return pos + shortcutByteSize(dict, pos); return pos + shortcutByteSize(dict, pos);
@ -264,7 +266,7 @@ inline int BinaryFormat::skipShortcuts(const uint8_t *const dict, const uint8_t
} }
} }
inline int BinaryFormat::skipBigrams(const uint8_t *const dict, const uint8_t flags, AK_FORCE_INLINE int BinaryFormat::skipBigrams(const uint8_t *const dict, const uint8_t flags,
const int pos) { const int pos) {
if (FLAG_HAS_BIGRAMS & flags) { if (FLAG_HAS_BIGRAMS & flags) {
return skipExistingBigrams(dict, pos); return skipExistingBigrams(dict, pos);
@ -273,7 +275,7 @@ inline int BinaryFormat::skipBigrams(const uint8_t *const dict, const uint8_t fl
} }
} }
inline int BinaryFormat::skipAllAttributes(const uint8_t *const dict, const uint8_t flags, AK_FORCE_INLINE int BinaryFormat::skipAllAttributes(const uint8_t *const dict, const uint8_t flags,
const int pos) { const int pos) {
// This function skips all attributes: shortcuts and bigrams. // This function skips all attributes: shortcuts and bigrams.
int newPos = pos; int newPos = pos;
@ -282,7 +284,7 @@ inline int BinaryFormat::skipAllAttributes(const uint8_t *const dict, const uint
return newPos; return newPos;
} }
inline int BinaryFormat::skipChildrenPosAndAttributes(const uint8_t *const dict, AK_FORCE_INLINE int BinaryFormat::skipChildrenPosAndAttributes(const uint8_t *const dict,
const uint8_t flags, const int pos) { const uint8_t flags, const int pos) {
int currentPos = pos; int currentPos = pos;
currentPos = skipChildrenPosition(flags, currentPos); currentPos = skipChildrenPosition(flags, currentPos);
@ -290,8 +292,8 @@ inline int BinaryFormat::skipChildrenPosAndAttributes(const uint8_t *const dict,
return currentPos; return currentPos;
} }
inline int BinaryFormat::readChildrenPosition(const uint8_t *const dict, const uint8_t flags, AK_FORCE_INLINE int BinaryFormat::readChildrenPosition(const uint8_t *const dict,
const int pos) { const uint8_t flags, const int pos) {
int offset = 0; int offset = 0;
switch (MASK_GROUP_ADDRESS_TYPE & flags) { switch (MASK_GROUP_ADDRESS_TYPE & flags) {
case FLAG_GROUP_ADDRESS_TYPE_ONEBYTE: case FLAG_GROUP_ADDRESS_TYPE_ONEBYTE:
@ -318,7 +320,7 @@ inline bool BinaryFormat::hasChildrenInFlags(const uint8_t flags) {
return (FLAG_GROUP_ADDRESS_TYPE_NOADDRESS != (MASK_GROUP_ADDRESS_TYPE & flags)); return (FLAG_GROUP_ADDRESS_TYPE_NOADDRESS != (MASK_GROUP_ADDRESS_TYPE & flags));
} }
inline int BinaryFormat::getAttributeAddressAndForwardPointer(const uint8_t *const dict, AK_FORCE_INLINE int BinaryFormat::getAttributeAddressAndForwardPointer(const uint8_t *const dict,
const uint8_t flags, int *pos) { const uint8_t flags, int *pos) {
int offset = 0; int offset = 0;
const int origin = *pos; const int origin = *pos;
@ -352,8 +354,8 @@ inline int BinaryFormat::getAttributeFrequencyFromFlags(const int flags) {
// This function gets the byte position of the last chargroup of the exact matching word in the // This function gets the byte position of the last chargroup of the exact matching word in the
// dictionary. If no match is found, it returns NOT_VALID_WORD. // dictionary. If no match is found, it returns NOT_VALID_WORD.
inline int BinaryFormat::getTerminalPosition(const uint8_t *const root, const int *const inWord, AK_FORCE_INLINE int BinaryFormat::getTerminalPosition(const uint8_t *const root,
const int length, const bool forceLowerCaseSearch) { const int *const inWord, const int length, const bool forceLowerCaseSearch) {
int pos = 0; int pos = 0;
int wordPos = 0; int wordPos = 0;
@ -438,7 +440,7 @@ inline int BinaryFormat::getTerminalPosition(const uint8_t *const root, const in
* outUnigramFrequency: a pointer to an int to write the frequency into. * outUnigramFrequency: a pointer to an int to write the frequency into.
* Return value : the length of the word, of 0 if the word was not found. * Return value : the length of the word, of 0 if the word was not found.
*/ */
inline int BinaryFormat::getWordAtAddress(const uint8_t *const root, const int address, AK_FORCE_INLINE int BinaryFormat::getWordAtAddress(const uint8_t *const root, const int address,
const int maxDepth, int *outWord, int *outUnigramFrequency) { const int maxDepth, int *outWord, int *outUnigramFrequency) {
int pos = 0; int pos = 0;
int wordPos = 0; int wordPos = 0;

View File

@ -56,7 +56,8 @@ class Correction {
// No need to initialize it explicitly here. // No need to initialize it explicitly here.
} }
virtual ~Correction() {} // Non virtual inline destructor -- never inherit this class
~Correction() {}
void resetCorrection(); void resetCorrection();
void initCorrection( void initCorrection(
const ProximityInfo *pi, const int inputSize, const int maxWordLength); const ProximityInfo *pi, const int inputSize, const int maxWordLength);

View File

@ -19,6 +19,8 @@
#include <cmath> #include <cmath>
#include "defines.h"
#define DEBUG_DECODER false #define DEBUG_DECODER false
#define M_PI_F 3.14159265f #define M_PI_F 3.14159265f
@ -44,19 +46,19 @@ static inline float getDistanceFloat(const float x1, const float y1, const float
return hypotf(x1 - x2, y1 - y2); return hypotf(x1 - x2, y1 - y2);
} }
static inline int getDistanceInt(const int x1, const int y1, const int x2, const int y2) { static AK_FORCE_INLINE int getDistanceInt(const int x1, const int y1, const int x2, const int y2) {
return static_cast<int>(getDistanceFloat(static_cast<float>(x1), static_cast<float>(y1), return static_cast<int>(getDistanceFloat(static_cast<float>(x1), static_cast<float>(y1),
static_cast<float>(x2), static_cast<float>(y2))); static_cast<float>(x2), static_cast<float>(y2)));
} }
static inline float getAngle(const int x1, const int y1, const int x2, const int y2) { static AK_FORCE_INLINE float getAngle(const int x1, const int y1, const int x2, const int y2) {
const int dx = x1 - x2; const int dx = x1 - x2;
const int dy = y1 - y2; const int dy = y1 - y2;
if (dx == 0 && dy == 0) return 0; if (dx == 0 && dy == 0) return 0;
return atan2f(static_cast<float>(dy), static_cast<float>(dx)); return atan2f(static_cast<float>(dy), static_cast<float>(dx));
} }
static inline float getAngleDiff(const float a1, const float a2) { static AK_FORCE_INLINE float getAngleDiff(const float a1, const float a2) {
const float deltaA = fabsf(a1 - a2); const float deltaA = fabsf(a1 - a2);
const float diff = ROUND_FLOAT_10000(deltaA); const float diff = ROUND_FLOAT_10000(deltaA);
if (diff > M_PI_F) { if (diff > M_PI_F) {

View File

@ -19,4 +19,8 @@
namespace latinime { namespace latinime {
IncrementalDecoderInterface * IncrementalDecoderInterface *
(*GestureDecoderWrapper::sGestureDecoderFactoryMethod)(int, int) = 0; (*GestureDecoderWrapper::sGestureDecoderFactoryMethod)(int, int) = 0;
GestureDecoderWrapper::~GestureDecoderWrapper() {
delete mIncrementalDecoderInterface;
}
} // namespace latinime } // namespace latinime

View File

@ -33,9 +33,7 @@ class GestureDecoderWrapper : public IncrementalDecoderInterface {
: mIncrementalDecoderInterface(getGestureDecoderInstance(maxWordLength, maxWords)) { : mIncrementalDecoderInterface(getGestureDecoderInstance(maxWordLength, maxWords)) {
} }
virtual ~GestureDecoderWrapper() { virtual ~GestureDecoderWrapper();
delete mIncrementalDecoderInterface;
}
int getSuggestions(ProximityInfo *pInfo, void *traverseSession, int *inputXs, int *inputYs, int getSuggestions(ProximityInfo *pInfo, void *traverseSession, int *inputXs, int *inputYs,
int *times, int *pointerIds, int *codes, int inputSize, int commitPoint, int *outWords, int *times, int *pointerIds, int *codes, int inputSize, int commitPoint, int *outWords,

View File

@ -19,4 +19,8 @@
namespace latinime { namespace latinime {
IncrementalDecoderInterface * IncrementalDecoderInterface *
(*IncrementalDecoderWrapper::sIncrementalDecoderFactoryMethod)(int, int) = 0; (*IncrementalDecoderWrapper::sIncrementalDecoderFactoryMethod)(int, int) = 0;
IncrementalDecoderWrapper::~IncrementalDecoderWrapper() {
delete mIncrementalDecoderInterface;
}
} // namespace latinime } // namespace latinime

View File

@ -33,9 +33,7 @@ class IncrementalDecoderWrapper : public IncrementalDecoderInterface {
: mIncrementalDecoderInterface(getIncrementalDecoderInstance(maxWordLength, maxWords)) { : mIncrementalDecoderInterface(getIncrementalDecoderInstance(maxWordLength, maxWords)) {
} }
virtual ~IncrementalDecoderWrapper() { virtual ~IncrementalDecoderWrapper();
delete mIncrementalDecoderInterface;
}
int getSuggestions(ProximityInfo *pInfo, void *traverseSession, int *inputXs, int *inputYs, int getSuggestions(ProximityInfo *pInfo, void *traverseSession, int *inputXs, int *inputYs,
int *times, int *pointerIds, int *codes, int inputSize, int commitPoint, int *outWords, int *times, int *pointerIds, int *codes, int inputSize, int commitPoint, int *outWords,

View File

@ -31,8 +31,8 @@ namespace latinime {
/* static */ const float ProximityInfo::NOT_A_DISTANCE_FLOAT = -1.0f; /* static */ const float ProximityInfo::NOT_A_DISTANCE_FLOAT = -1.0f;
static inline void safeGetOrFillZeroIntArrayRegion(JNIEnv *env, jintArray jArray, jsize len, static AK_FORCE_INLINE void safeGetOrFillZeroIntArrayRegion(JNIEnv *env, jintArray jArray,
jint *buffer) { jsize len, jint *buffer) {
if (jArray && buffer) { if (jArray && buffer) {
env->GetIntArrayRegion(jArray, 0, len, buffer); env->GetIntArrayRegion(jArray, 0, len, buffer);
} else if (buffer) { } else if (buffer) {
@ -40,8 +40,8 @@ static inline void safeGetOrFillZeroIntArrayRegion(JNIEnv *env, jintArray jArray
} }
} }
static inline void safeGetOrFillZeroFloatArrayRegion(JNIEnv *env, jfloatArray jArray, jsize len, static AK_FORCE_INLINE void safeGetOrFillZeroFloatArrayRegion(JNIEnv *env, jfloatArray jArray,
jfloat *buffer) { jsize len, jfloat *buffer) {
if (jArray && buffer) { if (jArray && buffer) {
env->GetFloatArrayRegion(jArray, 0, len, buffer); env->GetFloatArrayRegion(jArray, 0, len, buffer);
} else if (buffer) { } else if (buffer) {

View File

@ -50,7 +50,7 @@ class ProximityInfoState {
///////////////////////////////////////// /////////////////////////////////////////
// Defined here // // Defined here //
///////////////////////////////////////// /////////////////////////////////////////
ProximityInfoState() AK_FORCE_INLINE ProximityInfoState()
: mProximityInfo(0), mMaxPointToKeyLength(0), : mProximityInfo(0), mMaxPointToKeyLength(0),
mHasTouchPositionCorrectionData(false), mMostCommonKeyWidthSquare(0), mLocaleStr(), mHasTouchPositionCorrectionData(false), mMostCommonKeyWidthSquare(0), mLocaleStr(),
mKeyCount(0), mCellHeight(0), mCellWidth(0), mGridHeight(0), mGridWidth(0), mKeyCount(0), mCellHeight(0), mCellWidth(0), mGridHeight(0), mGridWidth(0),
@ -63,13 +63,14 @@ class ProximityInfoState {
memset(mPrimaryInputWord, 0, sizeof(mPrimaryInputWord)); memset(mPrimaryInputWord, 0, sizeof(mPrimaryInputWord));
} }
virtual ~ProximityInfoState() {} // Non virtual inline destructor -- never inherit this class
AK_FORCE_INLINE ~ProximityInfoState() {}
inline int getPrimaryCodePointAt(const int index) const { inline int getPrimaryCodePointAt(const int index) const {
return getProximityCodePointsAt(index)[0]; return getProximityCodePointsAt(index)[0];
} }
inline bool existsCodePointInProximityAt(const int index, const int c) const { AK_FORCE_INLINE bool existsCodePointInProximityAt(const int index, const int c) const {
const int *codePoints = getProximityCodePointsAt(index); const int *codePoints = getProximityCodePointsAt(index);
int i = 0; int i = 0;
while (codePoints[i] > 0 && i < MAX_PROXIMITY_CHARS_SIZE_INTERNAL) { while (codePoints[i] > 0 && i < MAX_PROXIMITY_CHARS_SIZE_INTERNAL) {

View File

@ -53,7 +53,8 @@ class WordsPriorityQueue {
} }
} }
virtual ~WordsPriorityQueue() { // Non virtual inline destructor -- never inherit this class
AK_FORCE_INLINE ~WordsPriorityQueue() {
delete[] mSuggestedWords; delete[] mSuggestedWords;
} }
@ -98,7 +99,7 @@ class WordsPriorityQueue {
return static_cast<int>(mSuggestions.size()); return static_cast<int>(mSuggestions.size());
} }
void clear() { AK_FORCE_INLINE void clear() {
mHighestSuggestedWord = 0; mHighestSuggestedWord = 0;
while (!mSuggestions.empty()) { while (!mSuggestions.empty()) {
SuggestedWord *sw = mSuggestions.top(); SuggestedWord *sw = mSuggestions.top();

View File

@ -36,7 +36,8 @@ class WordsPriorityQueuePool {
} }
} }
virtual ~WordsPriorityQueuePool() { // Non virtual inline destructor -- never inherit this class
~WordsPriorityQueuePool() {
// Note: these explicit calls to the destructor match the calls to placement new() above. // Note: these explicit calls to the destructor match the calls to placement new() above.
if (mMasterQueue) mMasterQueue->~WordsPriorityQueue(); if (mMasterQueue) mMasterQueue->~WordsPriorityQueue();
for (int i = 0; i < MULTIPLE_WORDS_SUGGESTION_MAX_WORDS * SUB_QUEUE_MAX_COUNT; ++i) { for (int i = 0; i < MULTIPLE_WORDS_SUGGESTION_MAX_WORDS * SUB_QUEUE_MAX_COUNT; ++i) {
@ -68,7 +69,7 @@ class WordsPriorityQueuePool {
} }
} }
inline void clearSubQueue(const int wordIndex) { AK_FORCE_INLINE void clearSubQueue(const int wordIndex) {
for (int i = 0; i < SUB_QUEUE_MAX_COUNT; ++i) { for (int i = 0; i < SUB_QUEUE_MAX_COUNT; ++i) {
WordsPriorityQueue *queue = getSubQueue(wordIndex, i); WordsPriorityQueue *queue = getSubQueue(wordIndex, i);
if (queue) { if (queue) {