Try to avoid allocation when interning strings.
This speeds up const-string operations when there are hash
conflicts in the DexCache string array and prevents throwing
OOME when the String has been previously allocated.
Test: Run ART test suite on host and Nexus 6.
Change-Id: Iaea46869d1f84bfc53c07659151203fc747e9643
diff --git a/runtime/intern_table.cc b/runtime/intern_table.cc
index 1940d67..be061be 100644
--- a/runtime/intern_table.cc
+++ b/runtime/intern_table.cc
@@ -316,8 +316,14 @@
mirror::String* InternTable::InternStrong(int32_t utf16_length, const char* utf8_data) {
DCHECK(utf8_data != nullptr);
+ Thread* self = Thread::Current();
+ // Try to avoid allocation.
+ mirror::String* s = LookupStrong(self, utf16_length, utf8_data);
+ if (s != nullptr) {
+ return s;
+ }
return InternStrong(mirror::String::AllocFromModifiedUtf8(
- Thread::Current(), utf16_length, utf8_data));
+ self, utf16_length, utf8_data));
}
mirror::String* InternTable::InternStrong(const char* utf8_data) {