diff options
| author | Claes Redestad <redestad@openjdk.org> | 2019-04-30 12:54:07 +0200 |
|---|---|---|
| committer | Claes Redestad <redestad@openjdk.org> | 2019-04-30 12:54:07 +0200 |
| commit | e7a6cbbd38e805e1880f3990f91a2c697899663a (patch) | |
| tree | 6f2878f7b78a783b025114b3ff6d4c233b3c2353 /src/java.base/share/classes/java/lang/StringConcatHelper.java | |
| parent | e3aa6f7907e058ae5236d2bdbc5c167dcc148c44 (diff) | |
| download | openjdk-e7a6cbbd38e805e1880f3990f91a2c697899663a.tar.gz openjdk-e7a6cbbd38e805e1880f3990f91a2c697899663a.zip | |
8222852: Reduce String concat combinator tree shapes by folding constants into prependers
Co-authored-by: Peter Levart <peter.levart@gmail.com>
Reviewed-by: shade, plevart, forax
Diffstat (limited to 'src/java.base/share/classes/java/lang/StringConcatHelper.java')
| -rw-r--r-- | src/java.base/share/classes/java/lang/StringConcatHelper.java | 131 |
1 files changed, 118 insertions, 13 deletions
diff --git a/src/java.base/share/classes/java/lang/StringConcatHelper.java b/src/java.base/share/classes/java/lang/StringConcatHelper.java index 469e17cd428..b0b263af5ec 100644 --- a/src/java.base/share/classes/java/lang/StringConcatHelper.java +++ b/src/java.base/share/classes/java/lang/StringConcatHelper.java @@ -144,7 +144,7 @@ final class StringConcatHelper { * @param value boolean value to encode * @return updated index (coder value retained) */ - static long prepend(long indexCoder, byte[] buf, boolean value) { + private static long prepend(long indexCoder, byte[] buf, boolean value) { int index = (int)indexCoder; if (indexCoder < UTF16) { if (value) { @@ -178,17 +178,41 @@ final class StringConcatHelper { } /** - * Prepends the stringly representation of byte value into buffer, + * Prepends constant and the stringly representation of value into buffer, * given the coder and final index. Index is measured in chars, not in bytes! * * @param indexCoder final char index in the buffer, along with coder packed * into higher bits. * @param buf buffer to append to - * @param value byte value to encode + * @param prefix a constant to prepend before value + * @param value boolean value to encode + * @param suffix a constant to prepend after value + * @return updated index (coder value retained) + */ + static long prepend(long indexCoder, byte[] buf, String prefix, boolean value, String suffix) { + if (suffix != null) indexCoder = prepend(indexCoder, buf, suffix); + indexCoder = prepend(indexCoder, buf, value); + if (prefix != null) indexCoder = prepend(indexCoder, buf, prefix); + return indexCoder; + } + + /** + * Prepends constant and the stringly representation of value into buffer, + * given the coder and final index. Index is measured in chars, not in bytes! + * + * @param indexCoder final char index in the buffer, along with coder packed + * into higher bits. + * @param buf buffer to append to + * @param prefix a constant to prepend before value + * @param value boolean value to encode + * @param suffix a constant to prepend after value * @return updated index (coder value retained) */ - static long prepend(long indexCoder, byte[] buf, byte value) { - return prepend(indexCoder, buf, (int)value); + static long prepend(long indexCoder, byte[] buf, String prefix, byte value, String suffix) { + if (suffix != null) indexCoder = prepend(indexCoder, buf, suffix); + indexCoder = prepend(indexCoder, buf, (int)value); + if (prefix != null) indexCoder = prepend(indexCoder, buf, prefix); + return indexCoder; } /** @@ -201,7 +225,7 @@ final class StringConcatHelper { * @param value char value to encode * @return updated index (coder value retained) */ - static long prepend(long indexCoder, byte[] buf, char value) { + private static long prepend(long indexCoder, byte[] buf, char value) { if (indexCoder < UTF16) { buf[(int)(--indexCoder)] = (byte) (value & 0xFF); } else { @@ -211,17 +235,41 @@ final class StringConcatHelper { } /** - * Prepends the stringly representation of short value into buffer, + * Prepends constant and the stringly representation of value into buffer, + * given the coder and final index. Index is measured in chars, not in bytes! + * + * @param indexCoder final char index in the buffer, along with coder packed + * into higher bits. + * @param buf buffer to append to + * @param prefix a constant to prepend before value + * @param value boolean value to encode + * @param suffix a constant to prepend after value + * @return updated index (coder value retained) + */ + static long prepend(long indexCoder, byte[] buf, String prefix, char value, String suffix) { + if (suffix != null) indexCoder = prepend(indexCoder, buf, suffix); + indexCoder = prepend(indexCoder, buf, value); + if (prefix != null) indexCoder = prepend(indexCoder, buf, prefix); + return indexCoder; + } + + /** + * Prepends constant and the stringly representation of value into buffer, * given the coder and final index. Index is measured in chars, not in bytes! * * @param indexCoder final char index in the buffer, along with coder packed * into higher bits. * @param buf buffer to append to - * @param value short value to encode + * @param prefix a constant to prepend before value + * @param value boolean value to encode + * @param suffix a constant to prepend after value * @return updated index (coder value retained) */ - static long prepend(long indexCoder, byte[] buf, short value) { - return prepend(indexCoder, buf, (int)value); + static long prepend(long indexCoder, byte[] buf, String prefix, short value, String suffix) { + if (suffix != null) indexCoder = prepend(indexCoder, buf, suffix); + indexCoder = prepend(indexCoder, buf, (int)value); + if (prefix != null) indexCoder = prepend(indexCoder, buf, prefix); + return indexCoder; } /** @@ -234,7 +282,7 @@ final class StringConcatHelper { * @param value integer value to encode * @return updated index (coder value retained) */ - static long prepend(long indexCoder, byte[] buf, int value) { + private static long prepend(long indexCoder, byte[] buf, int value) { if (indexCoder < UTF16) { return Integer.getChars(value, (int)indexCoder, buf); } else { @@ -243,6 +291,25 @@ final class StringConcatHelper { } /** + * Prepends constant and the stringly representation of value into buffer, + * given the coder and final index. Index is measured in chars, not in bytes! + * + * @param indexCoder final char index in the buffer, along with coder packed + * into higher bits. + * @param buf buffer to append to + * @param prefix a constant to prepend before value + * @param value boolean value to encode + * @param suffix a constant to prepend after value + * @return updated index (coder value retained) + */ + static long prepend(long indexCoder, byte[] buf, String prefix, int value, String suffix) { + if (suffix != null) indexCoder = prepend(indexCoder, buf, suffix); + indexCoder = prepend(indexCoder, buf, value); + if (prefix != null) indexCoder = prepend(indexCoder, buf, prefix); + return indexCoder; + } + + /** * Prepends the stringly representation of long value into buffer, * given the coder and final index. Index is measured in chars, not in bytes! * @@ -252,7 +319,7 @@ final class StringConcatHelper { * @param value long value to encode * @return updated index (coder value retained) */ - static long prepend(long indexCoder, byte[] buf, long value) { + private static long prepend(long indexCoder, byte[] buf, long value) { if (indexCoder < UTF16) { return Long.getChars(value, (int)indexCoder, buf); } else { @@ -261,6 +328,25 @@ final class StringConcatHelper { } /** + * Prepends constant and the stringly representation of value into buffer, + * given the coder and final index. Index is measured in chars, not in bytes! + * + * @param indexCoder final char index in the buffer, along with coder packed + * into higher bits. + * @param buf buffer to append to + * @param prefix a constant to prepend before value + * @param value boolean value to encode + * @param suffix a constant to prepend after value + * @return updated index (coder value retained) + */ + static long prepend(long indexCoder, byte[] buf, String prefix, long value, String suffix) { + if (suffix != null) indexCoder = prepend(indexCoder, buf, suffix); + indexCoder = prepend(indexCoder, buf, value); + if (prefix != null) indexCoder = prepend(indexCoder, buf, prefix); + return indexCoder; + } + + /** * Prepends the stringly representation of String value into buffer, * given the coder and final index. Index is measured in chars, not in bytes! * @@ -270,7 +356,7 @@ final class StringConcatHelper { * @param value String value to encode * @return updated index (coder value retained) */ - static long prepend(long indexCoder, byte[] buf, String value) { + private static long prepend(long indexCoder, byte[] buf, String value) { indexCoder -= value.length(); if (indexCoder < UTF16) { value.getBytes(buf, (int)indexCoder, String.LATIN1); @@ -281,6 +367,25 @@ final class StringConcatHelper { } /** + * Prepends constant and the stringly representation of value into buffer, + * given the coder and final index. Index is measured in chars, not in bytes! + * + * @param indexCoder final char index in the buffer, along with coder packed + * into higher bits. + * @param buf buffer to append to + * @param prefix a constant to prepend before value + * @param value boolean value to encode + * @param suffix a constant to prepend after value + * @return updated index (coder value retained) + */ + static long prepend(long indexCoder, byte[] buf, String prefix, String value, String suffix) { + if (suffix != null) indexCoder = prepend(indexCoder, buf, suffix); + indexCoder = prepend(indexCoder, buf, value); + if (prefix != null) indexCoder = prepend(indexCoder, buf, prefix); + return indexCoder; + } + + /** * Instantiates the String with given buffer and coder * @param buf buffer to use * @param indexCoder remaining index (should be zero) and coder |
