Remove unused variables

Since some variables with module LatinIME are defined but not used,
when compiled with build combination "sdk_pc_x86_64-userdebug" and
build command "mmm packages/inputmethods/LatinIME", the following
code lines will be reported that "variable 'XXX' set but not used".
(should be similar for all the other build combinations)

Repeated 10 times for each:
terminal_position_lookup_table.cpp:74:9 removedEntryCount
terminal_position_lookup_table.cpp:85:9 removedEntryCount
proximity_info_state_utils.cpp:493:9 tempTime
trie_map.cpp:56:9 unusedRegionSize
suggestion_results.cpp💯9 index

Repeated 80+ times:
proximity_info_utils.h:75:25 proximityChar

With this patch we are removing some of the unused variables and
putting the C++ 17 attribute [[maybe_unused]] to the others which
are used for logging. Then all the related build warnings have been
eliminated.

Test: mmm packages/inputmethods/LatinIME, presubmit check.

Change-Id: Ia66766322d6ae8a010b1cb55cc22993fbc6d012c
Signed-off-by: Jing Mike <jingyangliu@eswincomputing.com>
This commit is contained in:
Jing Mike 2023-02-20 15:43:42 +08:00 committed by Mike Jing
parent ce22ebc557
commit 03eef94a8d
6 changed files with 3 additions and 11 deletions

View File

@ -82,14 +82,12 @@ bool TerminalPositionLookupTable::flushToFile(const char *const dictPath) const
} }
bool TerminalPositionLookupTable::runGCTerminalIds(TerminalIdMap *const terminalIdMap) { bool TerminalPositionLookupTable::runGCTerminalIds(TerminalIdMap *const terminalIdMap) {
int removedEntryCount = 0;
int nextNewTerminalId = 0; int nextNewTerminalId = 0;
for (int i = 0; i < mSize; ++i) { for (int i = 0; i < mSize; ++i) {
const int terminalPos = getBuffer()->readUint( const int terminalPos = getBuffer()->readUint(
Ver4DictConstants::TERMINAL_ADDRESS_TABLE_ADDRESS_SIZE, getEntryPos(i)); Ver4DictConstants::TERMINAL_ADDRESS_TABLE_ADDRESS_SIZE, getEntryPos(i));
if (terminalPos == Ver4DictConstants::NOT_A_TERMINAL_ADDRESS) { if (terminalPos == Ver4DictConstants::NOT_A_TERMINAL_ADDRESS) {
// This entry is a garbage. // This entry is a garbage.
removedEntryCount++;
} else { } else {
// Give a new terminal id to the entry. // Give a new terminal id to the entry.
if (!getWritableBuffer()->writeUint(terminalPos, if (!getWritableBuffer()->writeUint(terminalPos,

View File

@ -71,14 +71,12 @@ bool TerminalPositionLookupTable::flushToFile(FILE *const file) const {
} }
bool TerminalPositionLookupTable::runGCTerminalIds(TerminalIdMap *const terminalIdMap) { bool TerminalPositionLookupTable::runGCTerminalIds(TerminalIdMap *const terminalIdMap) {
int removedEntryCount = 0;
int nextNewTerminalId = 0; int nextNewTerminalId = 0;
for (int i = 0; i < mSize; ++i) { for (int i = 0; i < mSize; ++i) {
const int terminalPos = getBuffer()->readUint( const int terminalPos = getBuffer()->readUint(
Ver4DictConstants::TERMINAL_ADDRESS_TABLE_ADDRESS_SIZE, getEntryPos(i)); Ver4DictConstants::TERMINAL_ADDRESS_TABLE_ADDRESS_SIZE, getEntryPos(i));
if (terminalPos == Ver4DictConstants::NOT_A_TERMINAL_ADDRESS) { if (terminalPos == Ver4DictConstants::NOT_A_TERMINAL_ADDRESS) {
// This entry is a garbage. // This entry is a garbage.
removedEntryCount++;
} else { } else {
// Give a new terminal id to the entry. // Give a new terminal id to the entry.
if (!getWritableBuffer()->writeUint(terminalPos, if (!getWritableBuffer()->writeUint(terminalPos,

View File

@ -53,7 +53,7 @@ void TrieMap::dump(const int from, const int to) const {
for (int i = from; i < to; ++i) { for (int i = from; i < to; ++i) {
AKLOGI("Entry[%d]: %x, %x", i, readField0(i), readField1(i)); AKLOGI("Entry[%d]: %x, %x", i, readField0(i), readField1(i));
} }
int unusedRegionSize = 0; [[maybe_unused]] int unusedRegionSize = 0;
for (int i = 1; i <= MAX_NUM_OF_ENTRIES_IN_ONE_LEVEL; ++i) { for (int i = 1; i <= MAX_NUM_OF_ENTRIES_IN_ONE_LEVEL; ++i) {
int index = readEmptyTableLink(i); int index = readEmptyTableLink(i);
while (index != ROOT_BITMAP_ENTRY_INDEX) { while (index != ROOT_BITMAP_ENTRY_INDEX) {

View File

@ -490,12 +490,10 @@ namespace latinime {
const int x0 = (*sampledInputXs)[id]; const int x0 = (*sampledInputXs)[id];
const int y0 = (*sampledInputYs)[id]; const int y0 = (*sampledInputYs)[id];
const int actualInputIndex = (*sampledInputIndices)[id]; const int actualInputIndex = (*sampledInputIndices)[id];
int tempTime = 0;
int tempBeelineDistance = 0; int tempBeelineDistance = 0;
int start = actualInputIndex; int start = actualInputIndex;
// lookup forward // lookup forward
while (start > 0 && tempBeelineDistance < lookupRadius) { while (start > 0 && tempBeelineDistance < lookupRadius) {
tempTime += times[start] - times[start - 1];
--start; --start;
tempBeelineDistance = GeometryUtils::getDistanceInt(x0, y0, xCoordinates[start], tempBeelineDistance = GeometryUtils::getDistanceInt(x0, y0, xCoordinates[start],
yCoordinates[start]); yCoordinates[start]);
@ -504,12 +502,10 @@ namespace latinime {
if (start > 0 && start < actualInputIndex) { if (start > 0 && start < actualInputIndex) {
++start; ++start;
} }
tempTime= 0;
tempBeelineDistance = 0; tempBeelineDistance = 0;
int end = actualInputIndex; int end = actualInputIndex;
// lookup backward // lookup backward
while (end < (inputSize - 1) && tempBeelineDistance < lookupRadius) { while (end < (inputSize - 1) && tempBeelineDistance < lookupRadius) {
tempTime += times[end + 1] - times[end];
++end; ++end;
tempBeelineDistance = GeometryUtils::getDistanceInt(x0, y0, xCoordinates[end], tempBeelineDistance = GeometryUtils::getDistanceInt(x0, y0, xCoordinates[end],
yCoordinates[end]); yCoordinates[end]);

View File

@ -72,7 +72,7 @@ class ProximityInfoUtils {
for (int i = 0; i < inputSize; ++i) { for (int i = 0; i < inputSize; ++i) {
AKLOGI("---"); AKLOGI("---");
for (int j = 0; j < MAX_PROXIMITY_CHARS_SIZE; ++j) { for (int j = 0; j < MAX_PROXIMITY_CHARS_SIZE; ++j) {
int proximityChar = [[maybe_unused]] int proximityChar =
inputProximities[i * MAX_PROXIMITY_CHARS_SIZE + j]; inputProximities[i * MAX_PROXIMITY_CHARS_SIZE + j];
proximityChar += 0; proximityChar += 0;
AKLOGI("--- (%d)%c", i, proximityChar); AKLOGI("--- (%d)%c", i, proximityChar);

View File

@ -97,7 +97,7 @@ void SuggestionResults::dumpSuggestions() const {
suggestedWords.push_back(copyOfSuggestedWords.top()); suggestedWords.push_back(copyOfSuggestedWords.top());
copyOfSuggestedWords.pop(); copyOfSuggestedWords.pop();
} }
int index = 0; [[maybe_unused]] int index = 0;
for (auto it = suggestedWords.rbegin(); it != suggestedWords.rend(); ++it) { for (auto it = suggestedWords.rbegin(); it != suggestedWords.rend(); ++it) {
DUMP_SUGGESTION(it->getCodePoint(), it->getCodePointCount(), index, it->getScore()); DUMP_SUGGESTION(it->getCodePoint(), it->getCodePointCount(), index, it->getScore());
index++; index++;