diff options
author | Ian Rogers <irogers@google.com> | 2014-01-03 19:06:08 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2014-01-03 19:06:08 +0000 |
commit | 5a2ced515a456f15dcf194843c024e835eda7dbe (patch) | |
tree | a965dd22d9005ca8f8f963d97fab3e2c8886ca05 | |
parent | 1fbbfa40187a9e761d846b5bccf88da62db0598b (diff) | |
parent | 4069d33b95b43df47a522ff52b35e901d4e58a56 (diff) | |
download | art-5a2ced515a456f15dcf194843c024e835eda7dbe.tar.gz art-5a2ced515a456f15dcf194843c024e835eda7dbe.tar.bz2 art-5a2ced515a456f15dcf194843c024e835eda7dbe.zip |
Merge "Use memcpy instead of Array::Set in mirror::String::AllocFromUtf16."
-rw-r--r-- | runtime/mirror/string.cc | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/runtime/mirror/string.cc b/runtime/mirror/string.cc index d6e509d841..1f756a1e53 100644 --- a/runtime/mirror/string.cc +++ b/runtime/mirror/string.cc @@ -121,20 +121,18 @@ String* String::AllocFromUtf16(Thread* self, int32_t utf16_length, const uint16_t* utf16_data_in, int32_t hash_code) { - CHECK(utf16_data_in != NULL || utf16_length == 0); + CHECK(utf16_data_in != nullptr || utf16_length == 0); String* string = Alloc(self, utf16_length); if (UNLIKELY(string == nullptr)) { return nullptr; } - // TODO: use 16-bit wide memset variant CharArray* array = const_cast<CharArray*>(string->GetCharArray()); - if (array == NULL) { - return NULL; - } - for (int i = 0; i < utf16_length; i++) { - array->Set(i, utf16_data_in[i]); + if (UNLIKELY(array == nullptr)) { + return nullptr; } + memcpy(array->GetData(), utf16_data_in, utf16_length * sizeof(uint16_t)); if (hash_code != 0) { + DCHECK_EQ(hash_code, ComputeUtf16Hash(utf16_data_in, utf16_length)); string->SetHashCode(hash_code); } else { string->ComputeHashCode(); |