mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8245969: Simplify String concat constant folding
Reviewed-by: psandoz, forax
This commit is contained in:
parent
69f7f95b93
commit
7e85b2c787
2 changed files with 78 additions and 72 deletions
|
@ -190,11 +190,9 @@ final class StringConcatHelper {
|
|||
* @param buf buffer to append to
|
||||
* @param value boolean value to encode
|
||||
* @param prefix a constant to prepend before value
|
||||
* @param suffix a constant to prepend after value
|
||||
* @return updated index (coder value retained)
|
||||
*/
|
||||
static long prepend(long indexCoder, byte[] buf, boolean value, String prefix, String suffix) {
|
||||
if (suffix != null) indexCoder = prepend(indexCoder, buf, suffix);
|
||||
static long prepend(long indexCoder, byte[] buf, boolean value, String prefix) {
|
||||
indexCoder = prepend(indexCoder, buf, value);
|
||||
if (prefix != null) indexCoder = prepend(indexCoder, buf, prefix);
|
||||
return indexCoder;
|
||||
|
@ -209,11 +207,9 @@ final class StringConcatHelper {
|
|||
* @param buf buffer to append to
|
||||
* @param value boolean value to encode
|
||||
* @param prefix a constant to prepend before value
|
||||
* @param suffix a constant to prepend after value
|
||||
* @return updated index (coder value retained)
|
||||
*/
|
||||
static long prepend(long indexCoder, byte[] buf, byte value, String prefix, String suffix) {
|
||||
if (suffix != null) indexCoder = prepend(indexCoder, buf, suffix);
|
||||
static long prepend(long indexCoder, byte[] buf, byte value, String prefix) {
|
||||
indexCoder = prepend(indexCoder, buf, (int)value);
|
||||
if (prefix != null) indexCoder = prepend(indexCoder, buf, prefix);
|
||||
return indexCoder;
|
||||
|
@ -247,11 +243,9 @@ final class StringConcatHelper {
|
|||
* @param buf buffer to append to
|
||||
* @param value boolean value to encode
|
||||
* @param prefix a constant to prepend before value
|
||||
* @param suffix a constant to prepend after value
|
||||
* @return updated index (coder value retained)
|
||||
*/
|
||||
static long prepend(long indexCoder, byte[] buf, char value, String prefix, String suffix) {
|
||||
if (suffix != null) indexCoder = prepend(indexCoder, buf, suffix);
|
||||
static long prepend(long indexCoder, byte[] buf, char value, String prefix) {
|
||||
indexCoder = prepend(indexCoder, buf, value);
|
||||
if (prefix != null) indexCoder = prepend(indexCoder, buf, prefix);
|
||||
return indexCoder;
|
||||
|
@ -266,11 +260,9 @@ final class StringConcatHelper {
|
|||
* @param buf buffer to append to
|
||||
* @param value boolean value to encode
|
||||
* @param prefix a constant to prepend before value
|
||||
* @param suffix a constant to prepend after value
|
||||
* @return updated index (coder value retained)
|
||||
*/
|
||||
static long prepend(long indexCoder, byte[] buf, short value, String prefix, String suffix) {
|
||||
if (suffix != null) indexCoder = prepend(indexCoder, buf, suffix);
|
||||
static long prepend(long indexCoder, byte[] buf, short value, String prefix) {
|
||||
indexCoder = prepend(indexCoder, buf, (int)value);
|
||||
if (prefix != null) indexCoder = prepend(indexCoder, buf, prefix);
|
||||
return indexCoder;
|
||||
|
@ -303,11 +295,9 @@ final class StringConcatHelper {
|
|||
* @param buf buffer to append to
|
||||
* @param value boolean value to encode
|
||||
* @param prefix a constant to prepend before value
|
||||
* @param suffix a constant to prepend after value
|
||||
* @return updated index (coder value retained)
|
||||
*/
|
||||
static long prepend(long indexCoder, byte[] buf, int value, String prefix, String suffix) {
|
||||
if (suffix != null) indexCoder = prepend(indexCoder, buf, suffix);
|
||||
static long prepend(long indexCoder, byte[] buf, int value, String prefix) {
|
||||
indexCoder = prepend(indexCoder, buf, value);
|
||||
if (prefix != null) indexCoder = prepend(indexCoder, buf, prefix);
|
||||
return indexCoder;
|
||||
|
@ -340,11 +330,9 @@ final class StringConcatHelper {
|
|||
* @param buf buffer to append to
|
||||
* @param value boolean value to encode
|
||||
* @param prefix a constant to prepend before value
|
||||
* @param suffix a constant to prepend after value
|
||||
* @return updated index (coder value retained)
|
||||
*/
|
||||
static long prepend(long indexCoder, byte[] buf, long value, String prefix, String suffix) {
|
||||
if (suffix != null) indexCoder = prepend(indexCoder, buf, suffix);
|
||||
static long prepend(long indexCoder, byte[] buf, long value, String prefix) {
|
||||
indexCoder = prepend(indexCoder, buf, value);
|
||||
if (prefix != null) indexCoder = prepend(indexCoder, buf, prefix);
|
||||
return indexCoder;
|
||||
|
@ -379,11 +367,9 @@ final class StringConcatHelper {
|
|||
* @param buf buffer to append to
|
||||
* @param value boolean value to encode
|
||||
* @param prefix a constant to prepend before value
|
||||
* @param suffix a constant to prepend after value
|
||||
* @return updated index (coder value retained)
|
||||
*/
|
||||
static long prepend(long indexCoder, byte[] buf, String value, String prefix, String suffix) {
|
||||
if (suffix != null) indexCoder = prepend(indexCoder, buf, suffix);
|
||||
static long prepend(long indexCoder, byte[] buf, String value, String prefix) {
|
||||
indexCoder = prepend(indexCoder, buf, value);
|
||||
if (prefix != null) indexCoder = prepend(indexCoder, buf, prefix);
|
||||
return indexCoder;
|
||||
|
@ -422,8 +408,8 @@ final class StringConcatHelper {
|
|||
String s2 = stringOf(second);
|
||||
// start "mixing" in length and coder or arguments, order is not
|
||||
// important
|
||||
long indexCoder = mix(initialCoder(), s2);
|
||||
indexCoder = mix(indexCoder, s1);
|
||||
long indexCoder = mix(initialCoder(), s1);
|
||||
indexCoder = mix(indexCoder, s2);
|
||||
byte[] buf = newArray(indexCoder);
|
||||
// prepend each argument in reverse order, since we prepending
|
||||
// from the end of the byte array
|
||||
|
@ -449,6 +435,28 @@ final class StringConcatHelper {
|
|||
|
||||
private static final Unsafe UNSAFE = Unsafe.getUnsafe();
|
||||
|
||||
/**
|
||||
* Allocates an uninitialized byte array based on the length and coder
|
||||
* information, then prepends the given suffix string at the end of the
|
||||
* byte array before returning it. The calling code must adjust the
|
||||
* indexCoder so that it's taken the coder of the suffix into account, but
|
||||
* subtracted the length of the suffix.
|
||||
*
|
||||
* @param suffix
|
||||
* @param indexCoder
|
||||
* @return the newly allocated byte array
|
||||
*/
|
||||
@ForceInline
|
||||
static byte[] newArrayWithSuffix(String suffix, long indexCoder) {
|
||||
byte[] buf = newArray(indexCoder + suffix.length());
|
||||
if (indexCoder < UTF16) {
|
||||
suffix.getBytes(buf, (int)indexCoder, String.LATIN1);
|
||||
} else {
|
||||
suffix.getBytes(buf, (int)indexCoder, String.UTF16);
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocates an uninitialized byte array based on the length and coder information
|
||||
* in indexCoder
|
||||
|
@ -478,5 +486,4 @@ final class StringConcatHelper {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue