Fill up a map of bigram addresses for lookup.
We don't want to do a linear search on each terminal when there
may be 100+ bigrams for a given word because that would be
disastrous for performance. Also, we need to resolve each bigram
address anyway.
This change resolves the addresses at first and puts them in a
balanced tree so that lookup will be O(log(n)).
Bug: 6313806
Change-Id: Ibf088035870b9acb41e948f0ab7af4726f2cee24
diff --git a/native/jni/src/debug.h b/native/jni/src/debug.h
index b13052c..376ba59 100644
--- a/native/jni/src/debug.h
+++ b/native/jni/src/debug.h
@@ -22,7 +22,7 @@
static inline unsigned char* convertToUnibyteString(unsigned short* input, unsigned char* output,
const unsigned int length) {
- int i = 0;
+ unsigned int i = 0;
for (; i <= length && input[i] != 0; ++i)
output[i] = input[i] & 0xFF;
output[i] = 0;
@@ -31,10 +31,10 @@
static inline unsigned char* convertToUnibyteStringAndReplaceLastChar(unsigned short* input,
unsigned char* output, const unsigned int length, unsigned char c) {
- int i = 0;
+ unsigned int i = 0;
for (; i <= length && input[i] != 0; ++i)
output[i] = input[i] & 0xFF;
- output[i-1] = c;
+ if (i > 0) output[i-1] = c;
output[i] = 0;
return output;
}