diff options
author | 2020-10-27 10:36:06 +0000 | |
---|---|---|
committer | 2020-10-28 09:43:42 +0000 | |
commit | 036b0708c12a33469db4a5adde9ded152b5eb700 (patch) | |
tree | 59fd4ce1126da0bec264431c1056f93eceb07c38 | |
parent | 8b2f7e67096c5a12f950f5ffe8f5ed4704299c57 (diff) |
Rename String.concat() implementation function.
Rename String::AllocFromStrings() to String::DoConcat() and
rename arguments to h_this and h_arg.
This addresses a comment from
https://android-review.googlesource.com/1473728 .
Test: testrunner.py --host --optimizing -t 021-string2
Bug: 169674485
Change-Id: I830541b64b51c0170aa5455cbad7cc86f4349f13
-rw-r--r-- | runtime/mirror/string.cc | 38 | ||||
-rw-r--r-- | runtime/mirror/string.h | 4 | ||||
-rw-r--r-- | runtime/native/java_lang_String.cc | 3 |
3 files changed, 20 insertions, 25 deletions
diff --git a/runtime/mirror/string.cc b/runtime/mirror/string.cc index 18ab1050ae..0ce45b855b 100644 --- a/runtime/mirror/string.cc +++ b/runtime/mirror/string.cc @@ -112,15 +112,13 @@ ObjPtr<String> String::DoReplace(Thread* self, Handle<String> src, uint16_t old_ return Alloc(self, length_with_flag, allocator_type, visitor); } -ObjPtr<String> String::AllocFromStrings(Thread* self, - Handle<String> string, - Handle<String> string2) { - int32_t length = string->GetLength(); - int32_t length2 = string2->GetLength(); +ObjPtr<String> String::DoConcat(Thread* self, Handle<String> h_this, Handle<String> h_arg) { + int32_t length_this = h_this->GetLength(); + int32_t length_arg = h_arg->GetLength(); gc::AllocatorType allocator_type = Runtime::Current()->GetHeap()->GetCurrentAllocator(); - const bool compressible = kUseStringCompression && - (string->IsCompressed() && string2->IsCompressed()); - const int32_t length_with_flag = String::GetFlaggedCount(length + length2, compressible); + const bool compressible = + kUseStringCompression && (h_this->IsCompressed() && h_arg->IsCompressed()); + const int32_t length_with_flag = String::GetFlaggedCount(length_this + length_arg, compressible); auto visitor = [=](ObjPtr<Object> obj, size_t usable_size) REQUIRES_SHARED(Locks::mutator_lock_) { SetStringCountVisitor set_string_count_visitor(length_with_flag); @@ -128,25 +126,25 @@ ObjPtr<String> String::AllocFromStrings(Thread* self, ObjPtr<String> new_string = obj->AsString(); if (compressible) { uint8_t* new_value = new_string->GetValueCompressed(); - memcpy(new_value, string->GetValueCompressed(), length * sizeof(uint8_t)); - memcpy(new_value + length, string2->GetValueCompressed(), length2 * sizeof(uint8_t)); + memcpy(new_value, h_this->GetValueCompressed(), length_this * sizeof(uint8_t)); + memcpy(new_value + length_this, h_arg->GetValueCompressed(), length_arg * sizeof(uint8_t)); } else { uint16_t* new_value = new_string->GetValue(); - if (string->IsCompressed()) { - const uint8_t* value = string->GetValueCompressed(); - for (int i = 0; i < length; ++i) { - new_value[i] = value[i]; + if (h_this->IsCompressed()) { + const uint8_t* value_this = h_this->GetValueCompressed(); + for (int i = 0; i < length_this; ++i) { + new_value[i] = value_this[i]; } } else { - memcpy(new_value, string->GetValue(), length * sizeof(uint16_t)); + memcpy(new_value, h_this->GetValue(), length_this * sizeof(uint16_t)); } - if (string2->IsCompressed()) { - const uint8_t* value2 = string2->GetValueCompressed(); - for (int i = 0; i < length2; ++i) { - new_value[i+length] = value2[i]; + if (h_arg->IsCompressed()) { + const uint8_t* value_arg = h_arg->GetValueCompressed(); + for (int i = 0; i < length_arg; ++i) { + new_value[i + length_this] = value_arg[i]; } } else { - memcpy(new_value + length, string2->GetValue(), length2 * sizeof(uint16_t)); + memcpy(new_value + length_this, h_arg->GetValue(), length_arg * sizeof(uint16_t)); } } }; diff --git a/runtime/mirror/string.h b/runtime/mirror/string.h index 0e3c500ca5..fd09e544f4 100644 --- a/runtime/mirror/string.h +++ b/runtime/mirror/string.h @@ -148,9 +148,7 @@ class MANAGED String final : public Object { gc::AllocatorType allocator_type) REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_); - static ObjPtr<String> AllocFromStrings(Thread* self, - Handle<String> string, - Handle<String> string2) + static ObjPtr<String> DoConcat(Thread* self, Handle<String> h_this, Handle<String> h_arg) REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_); static ObjPtr<String> AllocFromUtf16(Thread* self, diff --git a/runtime/native/java_lang_String.cc b/runtime/native/java_lang_String.cc index 7c7c5537fb..86f93299d9 100644 --- a/runtime/native/java_lang_String.cc +++ b/runtime/native/java_lang_String.cc @@ -60,8 +60,7 @@ static jstring String_concat(JNIEnv* env, jobject java_this, jstring java_string int32_t length_this = string_this->GetLength(); int32_t length_arg = string_arg->GetLength(); if (length_arg > 0 && length_this > 0) { - ObjPtr<mirror::String> result = - mirror::String::AllocFromStrings(soa.Self(), string_this, string_arg); + ObjPtr<mirror::String> result = mirror::String::DoConcat(soa.Self(), string_this, string_arg); return soa.AddLocalReference<jstring>(result); } jobject string_original = (length_this == 0) ? java_string_arg : java_this; |