summaryrefslogtreecommitdiff
path: root/runtime/utf.h
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/utf.h')
-rw-r--r--runtime/utf.h11
1 files changed, 10 insertions, 1 deletions
diff --git a/runtime/utf.h b/runtime/utf.h
index 27d2fd5f56..7c9c333126 100644
--- a/runtime/utf.h
+++ b/runtime/utf.h
@@ -82,7 +82,16 @@ void ConvertUtf16ToModifiedUtf8(char* utf8_out, size_t byte_count,
*/
int32_t ComputeUtf16Hash(mirror::CharArray* chars, int32_t offset, size_t char_count)
SHARED_REQUIRES(Locks::mutator_lock_);
-int32_t ComputeUtf16Hash(const uint16_t* chars, size_t char_count);
+
+template<typename MemoryType>
+int32_t ComputeUtf16Hash(const MemoryType* chars, size_t char_count) {
+ uint32_t hash = 0;
+ while (char_count--) {
+ hash = hash * 31 + *chars++;
+ }
+ return static_cast<int32_t>(hash);
+}
+
int32_t ComputeUtf16HashFromModifiedUtf8(const char* utf8, size_t utf16_length);
// Compute a hash code of a modified UTF-8 string. Not the standard java hash since it returns a