diff options
Diffstat (limited to 'src/java.base/share/classes/java/lang/StringConcatHelper.java')
| -rw-r--r-- | src/java.base/share/classes/java/lang/StringConcatHelper.java | 55 |
1 files changed, 31 insertions, 24 deletions
diff --git a/src/java.base/share/classes/java/lang/StringConcatHelper.java b/src/java.base/share/classes/java/lang/StringConcatHelper.java index 6c5ce33fecc..7e676307865 100644 --- a/src/java.base/share/classes/java/lang/StringConcatHelper.java +++ b/src/java.base/share/classes/java/lang/StringConcatHelper.java @@ -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 @@ -450,6 +436,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 * @param indexCoder @@ -478,5 +486,4 @@ final class StringConcatHelper { } } - } |
