Created
July 12, 2023 07:46
-
-
Save amaembo/83b4aeab1cd190f2e1dbd75eacb37443 to your computer and use it in GitHub Desktop.
String patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: src/java.base/share/classes/java/lang/AbstractStringBuilder.java | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
diff --git a/src/java.base/share/classes/java/lang/AbstractStringBuilder.java b/src/java.base/share/classes/java/lang/AbstractStringBuilder.java | |
--- a/src/java.base/share/classes/java/lang/AbstractStringBuilder.java (revision 674fa32cf8403ceec84bbe2c3f9404d612c10797) | |
+++ b/src/java.base/share/classes/java/lang/AbstractStringBuilder.java (date 1674682743075) | |
@@ -1680,8 +1680,8 @@ | |
return; | |
} | |
} | |
- this.coder = UTF16; | |
this.value = StringUTF16.toBytes(value, off, len); | |
+ this.coder = value.length == len ? LATIN1 : UTF16;; | |
} | |
final byte getCoder() { | |
Index: src/java.base/share/classes/java/lang/StringUTF16.java | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
diff --git a/src/java.base/share/classes/java/lang/StringUTF16.java b/src/java.base/share/classes/java/lang/StringUTF16.java | |
--- a/src/java.base/share/classes/java/lang/StringUTF16.java (revision 674fa32cf8403ceec84bbe2c3f9404d612c10797) | |
+++ b/src/java.base/share/classes/java/lang/StringUTF16.java (date 1689147746269) | |
@@ -25,9 +25,7 @@ | |
package java.lang; | |
-import java.util.Arrays; | |
-import java.util.Locale; | |
-import java.util.Spliterator; | |
+import java.util.*; | |
import java.util.function.Consumer; | |
import java.util.function.IntConsumer; | |
import java.util.stream.Stream; | |
@@ -150,10 +148,16 @@ | |
@IntrinsicCandidate | |
public static byte[] toBytes(char[] value, int off, int len) { | |
byte[] val = newBytesFor(len); | |
+ boolean hasNonLatin1 = false; | |
for (int i = 0; i < len; i++) { | |
- putChar(val, i, value[off]); | |
+ char c = value[off]; | |
+ hasNonLatin1 |= c > 0xFF; | |
+ putChar(val, i, c); | |
off++; | |
} | |
+ if (!hasNonLatin1) { | |
+ return Objects.requireNonNull(compress(val, 0, len)); | |
+ } | |
return val; | |
} | |
Index: src/java.base/share/classes/java/lang/String.java | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
diff --git a/src/java.base/share/classes/java/lang/String.java b/src/java.base/share/classes/java/lang/String.java | |
--- a/src/java.base/share/classes/java/lang/String.java (revision 674fa32cf8403ceec84bbe2c3f9404d612c10797) | |
+++ b/src/java.base/share/classes/java/lang/String.java (date 1677570581400) | |
@@ -660,8 +660,8 @@ | |
return; | |
} | |
} | |
- coder = UTF16; | |
value = StringUTF16.toBytes(ca, 0, clen); | |
+ coder = value.length == clen ? LATIN1 : UTF16; | |
return; | |
} | |
@@ -691,8 +691,8 @@ | |
return; | |
} | |
} | |
- coder = UTF16; | |
value = StringUTF16.toBytes(ca, 0, caLen); | |
+ coder = value.length == caLen ? LATIN1 : UTF16; | |
} | |
} | |
@@ -821,7 +821,8 @@ | |
return new String(bs, LATIN1); | |
} | |
} | |
- return new String(StringUTF16.toBytes(ca, 0, caLen), UTF16); | |
+ byte[] bytes = StringUTF16.toBytes(ca, 0, caLen); | |
+ return new String(bytes, bytes.length == caLen ? LATIN1 : UTF16); | |
} | |
private static final char REPL = '\ufffd'; | |
@@ -4523,8 +4524,8 @@ | |
return; | |
} | |
} | |
- this.coder = UTF16; | |
this.value = StringUTF16.toBytes(value, off, len); | |
+ this.coder = value.length == len ? LATIN1 : UTF16;; | |
} | |
/* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment