Verifier improvements.
Make type hierarchy for unresolved and unitialized types explicit.
Tidy and comment code.
Add DexFile::FindStringId that takes UTF-16 to avoid unnecessary UTF-8
conversions during image writing.
Explicitly disable RTTI that causes problems in debug builds.
Change-Id: I701f1c3be8be5854fcabf5ec39e9f9c5d388aab0
diff --git a/src/dex_file.cc b/src/dex_file.cc
index a8fb0e0..dad083c 100644
--- a/src/dex_file.cc
+++ b/src/dex_file.cc
@@ -436,7 +436,7 @@
return NULL;
}
-const DexFile::StringId* DexFile::FindStringId(const std::string& string) const {
+const DexFile::StringId* DexFile::FindStringId(const char* string) const {
int32_t lo = 0;
int32_t hi = NumStringIds() - 1;
while (hi >= lo) {
@@ -444,7 +444,27 @@
uint32_t length;
const DexFile::StringId& str_id = GetStringId(mid);
const char* str = GetStringDataAndLength(str_id, &length);
- int compare = CompareModifiedUtf8ToModifiedUtf8AsUtf16CodePointValues(string.c_str(), str);
+ int compare = CompareModifiedUtf8ToModifiedUtf8AsUtf16CodePointValues(string, str);
+ if (compare > 0) {
+ lo = mid + 1;
+ } else if (compare < 0) {
+ hi = mid - 1;
+ } else {
+ return &str_id;
+ }
+ }
+ return NULL;
+}
+
+const DexFile::StringId* DexFile::FindStringId(const uint16_t* string) const {
+ int32_t lo = 0;
+ int32_t hi = NumStringIds() - 1;
+ while (hi >= lo) {
+ int32_t mid = (hi + lo) / 2;
+ uint32_t length;
+ const DexFile::StringId& str_id = GetStringId(mid);
+ const char* str = GetStringDataAndLength(str_id, &length);
+ int compare = CompareModifiedUtf8ToUtf16AsCodePointValues(str, string);
if (compare > 0) {
lo = mid + 1;
} else if (compare < 0) {
@@ -544,7 +564,7 @@
descriptor += c;
} while (c != ';');
}
- const DexFile::StringId* string_id = FindStringId(descriptor);
+ const DexFile::StringId* string_id = FindStringId(descriptor.c_str());
if (string_id == NULL) {
return false;
}