summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXiaotao Duan <xiaotao@google.com>2009-05-04 12:30:17 +0800
committerXiaotao Duan <xiaotao@google.com>2009-05-04 12:30:17 +0800
commitc78dcdec607b4f50738a5b84fa170403e23c75ad (patch)
treec1445d2862c2f5427b5fc2c2a4eac7a7846383e1
parent8fb7e16cb2c271cb378c2d395594955369e2fb47 (diff)
downloadPinyinIME-c78dcdec607b4f50738a5b84fa170403e23c75ad.tar.gz
Replace unnecessary realloc()
Maximum length for a lemma is predefined and small. Runtime memory reallocation will lead to performance penalty. Predefined memory in stack is used insteadly.
-rw-r--r--jni/share/userdict.cpp13
1 files changed, 4 insertions, 9 deletions
diff --git a/jni/share/userdict.cpp b/jni/share/userdict.cpp
index 5064296..c3c7c98 100644
--- a/jni/share/userdict.cpp
+++ b/jni/share/userdict.cpp
@@ -1739,8 +1739,7 @@ int UserDict::put_lemmas_no_sync_from_utf16le_string(char16 * lemmas, int len) {
char16 * p = ptr, * py16 = ptr;
char16 * hz16 = NULL;
int py16_len = 0;
- uint16 * splid = NULL;
- int splid_size = 0;
+ uint16 splid[kMaxLemmaSize];
int splid_len = 0;
int hz16_len = 0;
char16 * fr16 = NULL;
@@ -1759,16 +1758,12 @@ int UserDict::put_lemmas_no_sync_from_utf16le_string(char16 * lemmas, int len) {
if (p - ptr == len)
break;
py16_len = p - py16;
- if (splid_size < splid_len) {
- char16 * tid = (char16*)realloc(splid, splid_len * 2);
- if (!tid)
- break;
- splid = tid;
- splid_size = splid_len * 2;
+ if (kMaxLemmaSize < splid_len) {
+ break;
}
bool is_pre;
int splidl = spl_parser->splstr16_to_idxs_f(
- py16, py16_len, splid, NULL, splid_size, is_pre);
+ py16, py16_len, splid, NULL, kMaxLemmaSize, is_pre);
if (splidl != splid_len)
break;
// Phrase