diff options
| author | 2016-03-30 14:01:24 +0000 | |
|---|---|---|
| committer | 2016-03-30 14:01:24 +0000 | |
| commit | 0b92b73c62ab4cc13ca040d4233fa69d182971cc (patch) | |
| tree | df7d6180b13430de8f255884b12f29f191d1468e /runtime/utf.cc | |
| parent | 01098af7a530ca65dcf5a40b3799c5147e49bd64 (diff) | |
| parent | 085055f933d76579c32586488951a4497ffcf10e (diff) | |
Merge "Optimizing: Improve const-string code generation."
am: 085055f
* commit '085055f933d76579c32586488951a4497ffcf10e':
Optimizing: Improve const-string code generation.
Change-Id: Idd5a215e18abba1e2161f1848cb08aefb4719cf0
Diffstat (limited to 'runtime/utf.cc')
| -rw-r--r-- | runtime/utf.cc | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/runtime/utf.cc b/runtime/utf.cc index a2d6363c6e..5e9fdf7fc8 100644 --- a/runtime/utf.cc +++ b/runtime/utf.cc @@ -178,6 +178,23 @@ int32_t ComputeUtf16Hash(const uint16_t* chars, size_t char_count) { return static_cast<int32_t>(hash); } +int32_t ComputeUtf16HashFromModifiedUtf8(const char* utf8, size_t utf16_length) { + uint32_t hash = 0; + while (utf16_length != 0u) { + const uint32_t pair = GetUtf16FromUtf8(&utf8); + const uint16_t first = GetLeadingUtf16Char(pair); + hash = hash * 31 + first; + --utf16_length; + const uint16_t second = GetTrailingUtf16Char(pair); + if (second != 0) { + hash = hash * 31 + second; + DCHECK_NE(utf16_length, 0u); + --utf16_length; + } + } + return static_cast<int32_t>(hash); +} + uint32_t ComputeModifiedUtf8Hash(const char* chars) { uint32_t hash = 0; while (*chars != '\0') { |