summaryrefslogtreecommitdiffstats
path: root/runtime
diff options
context:
space:
mode:
authorBrian Carlstrom <bdc@google.com>2013-09-06 15:42:40 -0700
committerBrian Carlstrom <bdc@google.com>2013-09-06 15:44:12 -0700
commit0a02d12788c0b21d020b67d65552ff692104be77 (patch)
tree30f80e44c0feab5d4a03d6de182244c7340aa136 /runtime
parent2e450bf45e1bacc9c356f6ab239ccfb31bd8d7e4 (diff)
downloadart-0a02d12788c0b21d020b67d65552ff692104be77.zip
art-0a02d12788c0b21d020b67d65552ff692104be77.tar.gz
art-0a02d12788c0b21d020b67d65552ff692104be77.tar.bz2
Revert "Revert "Remove bogus fastpath from String::Equals(const StringPiece&)""
This reverts commit 2b25433c561ff53494e948f20a221143b3165a14. Bug: 10614658 Change-Id: I757329f8643bf5e32a7d3005f8314fb9ebea440c
Diffstat (limited to 'runtime')
-rw-r--r--runtime/mirror/object_test.cc17
-rw-r--r--runtime/mirror/string.cc3
2 files changed, 9 insertions, 11 deletions
diff --git a/runtime/mirror/object_test.cc b/runtime/mirror/object_test.cc
index 814305c..b8765af 100644
--- a/runtime/mirror/object_test.cc
+++ b/runtime/mirror/object_test.cc
@@ -42,26 +42,27 @@ namespace mirror {
class ObjectTest : public CommonTest {
protected:
- void AssertString(int32_t length,
+ void AssertString(int32_t expected_utf16_length,
const char* utf8_in,
const char* utf16_expected_le,
int32_t expected_hash)
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
- UniquePtr<uint16_t[]> utf16_expected(new uint16_t[length]);
- for (int32_t i = 0; i < length; i++) {
+ UniquePtr<uint16_t[]> utf16_expected(new uint16_t[expected_utf16_length]);
+ for (int32_t i = 0; i < expected_utf16_length; i++) {
uint16_t ch = (((utf16_expected_le[i*2 + 0] & 0xff) << 8) |
((utf16_expected_le[i*2 + 1] & 0xff) << 0));
utf16_expected[i] = ch;
}
Thread* self = Thread::Current();
- SirtRef<String> string(self, String::AllocFromModifiedUtf8(self, length, utf8_in));
- ASSERT_EQ(length, string->GetLength());
+ SirtRef<String> string(self, String::AllocFromModifiedUtf8(self, expected_utf16_length, utf8_in));
+ ASSERT_EQ(expected_utf16_length, string->GetLength());
ASSERT_TRUE(string->GetCharArray() != NULL);
ASSERT_TRUE(string->GetCharArray()->GetData() != NULL);
- // strlen is necessary because the 1-character string "\0" is interpreted as ""
- ASSERT_TRUE(string->Equals(utf8_in) || length != static_cast<int32_t>(strlen(utf8_in)));
- for (int32_t i = 0; i < length; i++) {
+ // strlen is necessary because the 1-character string "\x00\x00" is interpreted as ""
+ ASSERT_TRUE(string->Equals(utf8_in) || (expected_utf16_length == 1 && strlen(utf8_in) == 0));
+ ASSERT_TRUE(string->Equals(StringPiece(utf8_in)) || (expected_utf16_length == 1 && strlen(utf8_in) == 0));
+ for (int32_t i = 0; i < expected_utf16_length; i++) {
EXPECT_EQ(utf16_expected[i], string->CharAt(i));
}
EXPECT_EQ(expected_hash, string->GetHashCode());
diff --git a/runtime/mirror/string.cc b/runtime/mirror/string.cc
index 54ba3b0..f8a0e53 100644
--- a/runtime/mirror/string.cc
+++ b/runtime/mirror/string.cc
@@ -224,9 +224,6 @@ bool String::Equals(const char* modified_utf8) const {
}
bool String::Equals(const StringPiece& modified_utf8) const {
- if (modified_utf8.size() != GetLength()) {
- return false;
- }
const char* p = modified_utf8.data();
for (int32_t i = 0; i < GetLength(); ++i) {
uint16_t ch = GetUtf16FromUtf8(&p);