diff options
author | Vladimir Marko <vmarko@google.com> | 2015-02-11 10:06:21 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2015-02-11 10:06:21 +0000 |
commit | 5a3399deaf448c8434d9ba0916ff799b1b791d95 (patch) | |
tree | b6075870aaee70635b3d7e3714072808e042bad7 | |
parent | aa874e0bbfb21aec0661b93cb1c2ce065bc20302 (diff) | |
parent | a48aef4234768ed37828df613919391c21f561a7 (diff) | |
download | art-5a3399deaf448c8434d9ba0916ff799b1b791d95.tar.gz art-5a3399deaf448c8434d9ba0916ff799b1b791d95.tar.bz2 art-5a3399deaf448c8434d9ba0916ff799b1b791d95.zip |
Merge "Fix ImageWriter::ComputeEagerResolvedStringsCallback()."
-rw-r--r-- | compiler/image_writer.cc | 5 | ||||
-rw-r--r-- | runtime/dex_file.cc | 4 | ||||
-rw-r--r-- | runtime/dex_file.h | 2 | ||||
-rw-r--r-- | runtime/utf.cc | 14 | ||||
-rw-r--r-- | runtime/utf.h | 7 |
5 files changed, 18 insertions, 14 deletions
diff --git a/compiler/image_writer.cc b/compiler/image_writer.cc index 670b76c38..c588e1a53 100644 --- a/compiler/image_writer.cc +++ b/compiler/image_writer.cc @@ -563,6 +563,7 @@ void ImageWriter::ComputeEagerResolvedStringsCallback(Object* obj, void* arg ATT } mirror::String* string = obj->AsString(); const uint16_t* utf16_string = string->GetCharArray()->GetData() + string->GetOffset(); + size_t utf16_length = static_cast<size_t>(string->GetLength()); ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); ReaderMutexLock mu(Thread::Current(), *class_linker->DexLock()); size_t dex_cache_count = class_linker->GetDexCacheCount(); @@ -570,10 +571,10 @@ void ImageWriter::ComputeEagerResolvedStringsCallback(Object* obj, void* arg ATT DexCache* dex_cache = class_linker->GetDexCache(i); const DexFile& dex_file = *dex_cache->GetDexFile(); const DexFile::StringId* string_id; - if (UNLIKELY(string->GetLength() == 0)) { + if (UNLIKELY(utf16_length == 0)) { string_id = dex_file.FindStringId(""); } else { - string_id = dex_file.FindStringId(utf16_string); + string_id = dex_file.FindStringId(utf16_string, utf16_length); } if (string_id != nullptr) { // This string occurs in this dex file, assign the dex cache entry. diff --git a/runtime/dex_file.cc b/runtime/dex_file.cc index dc85f6c2c..94d62db9e 100644 --- a/runtime/dex_file.cc +++ b/runtime/dex_file.cc @@ -578,14 +578,14 @@ const DexFile::StringId* DexFile::FindStringId(const char* string) const { return NULL; } -const DexFile::StringId* DexFile::FindStringId(const uint16_t* string) const { +const DexFile::StringId* DexFile::FindStringId(const uint16_t* string, size_t length) const { int32_t lo = 0; int32_t hi = NumStringIds() - 1; while (hi >= lo) { int32_t mid = (hi + lo) / 2; const DexFile::StringId& str_id = GetStringId(mid); const char* str = GetStringData(str_id); - int compare = CompareModifiedUtf8ToUtf16AsCodePointValues(str, string); + int compare = CompareModifiedUtf8ToUtf16AsCodePointValues(str, string, length); if (compare > 0) { lo = mid + 1; } else if (compare < 0) { diff --git a/runtime/dex_file.h b/runtime/dex_file.h index 9b8f25444..e121a0858 100644 --- a/runtime/dex_file.h +++ b/runtime/dex_file.h @@ -499,7 +499,7 @@ class DexFile { const StringId* FindStringId(const char* string) const; // Looks up a string id for a given utf16 string. - const StringId* FindStringId(const uint16_t* string) const; + const StringId* FindStringId(const uint16_t* string, size_t length) const; // Returns the number of type identifiers in the .dex file. uint32_t NumTypeIds() const { diff --git a/runtime/utf.cc b/runtime/utf.cc index 05b847b80..7ff296bf0 100644 --- a/runtime/utf.cc +++ b/runtime/utf.cc @@ -93,16 +93,18 @@ size_t ComputeModifiedUtf8Hash(const char* chars) { return static_cast<int32_t>(hash); } -int CompareModifiedUtf8ToUtf16AsCodePointValues(const char* utf8_1, const uint16_t* utf8_2) { +int CompareModifiedUtf8ToUtf16AsCodePointValues(const char* utf8, const uint16_t* utf16, + size_t utf16_length) { for (;;) { - if (*utf8_1 == '\0') { - return (*utf8_2 == '\0') ? 0 : -1; - } else if (*utf8_2 == '\0') { + if (*utf8 == '\0') { + return (utf16_length == 0) ? 0 : -1; + } else if (utf16_length == 0) { return 1; } - int c1 = GetUtf16FromUtf8(&utf8_1); - int c2 = *utf8_2; + int c1 = GetUtf16FromUtf8(&utf8); + int c2 = *utf16++; + --utf16_length; if (c1 != c2) { return c1 > c2 ? 1 : -1; diff --git a/runtime/utf.h b/runtime/utf.h index b55227bc4..3ee07fe65 100644 --- a/runtime/utf.h +++ b/runtime/utf.h @@ -59,10 +59,11 @@ ALWAYS_INLINE int CompareModifiedUtf8ToModifiedUtf8AsUtf16CodePointValues(const const char* utf8_2); /* - * Compare a modified UTF-8 string with a UTF-16 string as code point values in a non-locale - * sensitive manner. + * Compare a null-terminated modified UTF-8 string with a UTF-16 string (not null-terminated) + * as code point values in a non-locale sensitive manner. */ -int CompareModifiedUtf8ToUtf16AsCodePointValues(const char* utf8_1, const uint16_t* utf8_2); +int CompareModifiedUtf8ToUtf16AsCodePointValues(const char* utf8, const uint16_t* utf16, + size_t utf16_length); /* * Convert from UTF-16 to Modified UTF-8. Note that the output is _not_ |