aboutsummaryrefslogtreecommitdiffstats
path: root/native/jni/src/defines.h
diff options
context:
space:
mode:
authorSatoshi Kataoka <satok@google.com>2012-08-06 16:04:07 +0900
committerSatoshi Kataoka <satok@google.com>2012-08-06 16:04:07 +0900
commit44456dcbf23c29b54e9372d932b79805957724cb (patch)
treea8167c70e9d7017f212066cf2364d1ad5b09fdca /native/jni/src/defines.h
parent07e4f9eb530a795efd97986e28546c8c5e895c72 (diff)
parentd299bde24b4afd3955fa65c7ab372807a336c6df (diff)
downloadlatinime-44456dcbf23c29b54e9372d932b79805957724cb.tar.gz
latinime-44456dcbf23c29b54e9372d932b79805957724cb.tar.xz
latinime-44456dcbf23c29b54e9372d932b79805957724cb.zip
Merge remote-tracking branch 'goog/master' into mergescriptpackage
Conflicts: java/res/values-af/strings.xml java/res/values-cs/strings.xml java/res/values-et/strings.xml java/res/values-fi/strings.xml java/res/values-hi/strings.xml java/res/values-hr/strings.xml java/res/values-hu/strings.xml java/res/values-in/strings.xml java/res/values-ja/strings.xml java/res/values-ko/strings.xml java/res/values-lt/strings.xml java/res/values-lv/strings.xml java/res/values-ms/strings.xml java/res/values-pt/strings.xml java/res/values-ro/strings.xml java/res/values-ru/strings.xml java/res/values-sk/strings.xml java/res/values-sl/strings.xml java/res/values-sr/strings.xml java/res/values-sw/strings.xml java/res/values-tr/strings.xml java/res/values-vi/strings.xml java/res/values-zh-rCN/strings.xml java/res/values-zh-rTW/strings.xml Change-Id: Ib4141aca0b35148d62d22d4f32309f890c84303a
Diffstat (limited to 'native/jni/src/defines.h')
-rw-r--r--native/jni/src/defines.h99
1 files changed, 66 insertions, 33 deletions
diff --git a/native/jni/src/defines.h b/native/jni/src/defines.h
index c7d3bf313..31dd61e30 100644
--- a/native/jni/src/defines.h
+++ b/native/jni/src/defines.h
@@ -1,42 +1,79 @@
/*
-**
-** Copyright 2010, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-** http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
+ * Copyright (C) 2010, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
#ifndef LATINIME_DEFINES_H
#define LATINIME_DEFINES_H
#if defined(FLAG_DO_PROFILE) || defined(FLAG_DBG)
-#include <cutils/log.h>
-#define AKLOGE ALOGE
-#define AKLOGI ALOGI
+#include <android/log.h>
+#ifndef LOG_TAG
+#define LOG_TAG "LatinIME: "
+#endif
+#define AKLOGE(fmt, ...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, fmt, ##__VA_ARGS__)
+#define AKLOGI(fmt, ...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, fmt, ##__VA_ARGS__)
+#define DUMP_RESULT(words, frequencies, maxWordCount, maxWordLength) do { \
+ dumpResult(words, frequencies, maxWordCount, maxWordLength); } while(0)
#define DUMP_WORD(word, length) do { dumpWord(word, length); } while(0)
#define DUMP_WORD_INT(word, length) do { dumpWordInt(word, length); } while(0)
-static inline void dumpWord(const unsigned short* word, const int length) {
+static inline void dumpWordInfo(const unsigned short *word, const int length,
+ const int rank, const int frequency) {
static char charBuf[50];
+ int i = 0;
+ for (; i < length; ++i) {
+ const unsigned short c = word[i];
+ if (c == 0) {
+ break;
+ }
+ charBuf[i] = c;
+ }
+ charBuf[i] = 0;
+ if (i > 1) {
+ AKLOGI("%2d [ %s ] (%d)", rank, charBuf, frequency);
+ }
+}
- for (int i = 0; i < length; ++i) {
- charBuf[i] = word[i];
+static inline void dumpResult(
+ const unsigned short *outWords, const int *frequencies, const int maxWordCounts,
+ const int maxWordLength) {
+ AKLOGI("--- DUMP RESULT ---------");
+ for (int i = 0; i < maxWordCounts; ++i) {
+ dumpWordInfo(&outWords[i * maxWordLength], maxWordLength, i, frequencies[i]);
}
- charBuf[length] = 0;
- AKLOGI("[ %s ]", charBuf);
+ AKLOGI("-------------------------");
}
-static inline void dumpWordInt(const int* word, const int length) {
+static inline void dumpWord(const unsigned short *word, const int length) {
+ static char charBuf[50];
+ int i = 0;
+ for (; i < length; ++i) {
+ const unsigned short c = word[i];
+ if (c == 0) {
+ break;
+ }
+ charBuf[i] = c;
+ }
+ charBuf[i] = 0;
+ if (i > 1) {
+ AKLOGI("[ %s ]", charBuf);
+ }
+}
+
+static inline void dumpWordInt(const int *word, const int length) {
static char charBuf[50];
for (int i = 0; i < length; ++i) {
@@ -49,6 +86,7 @@ static inline void dumpWordInt(const int* word, const int length) {
#else
#define AKLOGE(fmt, ...)
#define AKLOGI(fmt, ...)
+#define DUMP_RESULT(words, frequencies, maxWordCount, maxWordLength)
#define DUMP_WORD(word, length)
#define DUMP_WORD_INT(word, length)
#endif
@@ -86,17 +124,18 @@ static inline void prof_out(void) {
AKLOGI("Error: You must call PROF_OPEN before PROF_CLOSE.");
}
AKLOGI("Total time is %6.3f ms.",
- profile_buf[PROF_BUF_SIZE - 1] * 1000 / (float)CLOCKS_PER_SEC);
+ profile_buf[PROF_BUF_SIZE - 1] * 1000.0f / static_cast<float>(CLOCKS_PER_SEC));
float all = 0;
for (int i = 0; i < PROF_BUF_SIZE - 1; ++i) {
all += profile_buf[i];
}
if (all == 0) all = 1;
for (int i = 0; i < PROF_BUF_SIZE - 1; ++i) {
- if (profile_buf[i] != 0) {
+ if (profile_buf[i]) {
AKLOGI("(%d): Used %4.2f%%, %8.4f ms. Called %d times.",
i, (profile_buf[i] * 100 / all),
- profile_buf[i] * 1000 / (float)CLOCKS_PER_SEC, profile_counter[i]);
+ profile_buf[i] * 1000.0f / static_cast<float>(CLOCKS_PER_SEC),
+ profile_counter[i]);
}
}
}
@@ -116,10 +155,6 @@ static inline void prof_out(void) {
#endif // FLAG_DO_PROFILE
#ifdef FLAG_DBG
-#include <cutils/log.h>
-#ifndef LOG_TAG
-#define LOG_TAG "LatinIME: "
-#endif
#define DEBUG_DICT true
#define DEBUG_DICT_FULL false
#define DEBUG_EDIT_DISTANCE false
@@ -146,7 +181,6 @@ static inline void prof_out(void) {
#define DEBUG_CORRECTION_FREQ false
#define DEBUG_WORDS_PRIORITY_QUEUE false
-
#endif // FLAG_DBG
#ifndef U_SHORT_MAX
@@ -313,5 +347,4 @@ typedef enum {
// Additional proximity char which can differ by language.
ADDITIONAL_PROXIMITY_CHAR
} ProximityType;
-
#endif // LATINIME_DEFINES_H