diff options
author | 2022-10-03 09:47:04 +0000 | |
---|---|---|
committer | 2022-10-03 14:19:38 +0000 | |
commit | 729277fa70c8a722e7ca7a319ecf9dc8a1ad9303 (patch) | |
tree | 9de7a4fcc4de31ce911829e89ff1726f0ee361c9 | |
parent | 15294fe689c98f1b1314013a6ae17ee26b59aa07 (diff) |
Fix `String` ctor with `hibyte` for empty strings.
Mark empty strings as compressed for any value of `hibyte`.
Test: New test in 021-string2.
Test: testrunner.py --host --optimizing -t 021-string2
Bug: 250530521
Change-Id: Ie129fba599a24021eda0a4a81a39fd3fc3769597
-rw-r--r-- | runtime/mirror/string-alloc-inl.h | 4 | ||||
-rw-r--r-- | test/021-string2/src/Main.java | 6 |
2 files changed, 9 insertions, 1 deletions
diff --git a/runtime/mirror/string-alloc-inl.h b/runtime/mirror/string-alloc-inl.h index 533053d934..925427a73b 100644 --- a/runtime/mirror/string-alloc-inl.h +++ b/runtime/mirror/string-alloc-inl.h @@ -216,7 +216,9 @@ inline ObjPtr<String> String::AllocFromByteArray(Thread* self, const uint8_t* const src = reinterpret_cast<uint8_t*>(array->GetData()) + offset; high_byte &= 0xff; // Extract the relevant bits before determining `compressible`. const bool compressible = - kUseStringCompression && String::AllASCII<uint8_t>(src, byte_length) && (high_byte == 0); + kUseStringCompression && + String::AllASCII<uint8_t>(src, byte_length) && + (high_byte == 0 || byte_length == 0); const int32_t length_with_flag = String::GetFlaggedCount(byte_length, compressible); SetStringCountAndBytesVisitor visitor(length_with_flag, array, offset, high_byte << 8); return Alloc<kIsInstrumented>(self, length_with_flag, allocator_type, visitor); diff --git a/test/021-string2/src/Main.java b/test/021-string2/src/Main.java index 39595f3280..5da10ca722 100644 --- a/test/021-string2/src/Main.java +++ b/test/021-string2/src/Main.java @@ -119,6 +119,7 @@ public class Main { testEqualsConstString(); testConstStringEquals(); testStringConcat(); + testEmptyWithHighByte(); // Regression tests for String.setCharAt() breaking string compression invariants. Locale en_US = new Locale("en", "US"); @@ -760,6 +761,11 @@ public class Main { Assert.assertEquals("abc\u0440xyzw\u0440", "abc\u0440".concat("xyzw\u0440")); } + public static void testEmptyWithHighByte() { + String empty = new String(new byte[0], 1); + Assert.assertEquals("", empty); + } + public static boolean $noinline$equalsConstString0(String s) { return s.equals(""); } |