RFR: 8316150: Refactor get chars and string size [v9]
温绍锦
duke at openjdk.org
Sat Sep 23 10:03:11 UTC 2023
On Sat, 23 Sep 2023 09:47:42 GMT, 温绍锦 <duke at openjdk.org> wrote:
>> 1. Reduce duplicate stringSize code
>> 2. Move java.lang.StringLatin1.getChars to jdk.internal.util.DecimalDigits::getCharLatin1,not only java.lang, other packages also need to use this method
>
> 温绍锦 has updated the pull request incrementally with one additional commit since the last revision:
>
> refactor HexDigits & OctalDigits & FormatItem, FormatItem#prepend provides two implementations: prependLatin1 and prependUTF16 [v2]
> Since the current `MethodHandle`-based char putter can only put 1-byte at once, have you considered something like this:
>
> ```java
> // A replacement for setter MethodHandle, or VarHandle, to accept multiple value types
> public interface DigitConsumer {
> void putChar(byte[] array, int index, byte value);
> // put 2 byte-sized chars at once, encoded little endian
> void putChar2(byte[] array, int index, short value);
> // you can add putChar4, putChar8, etc. if you need
> }
> ```
>
> and `StringConcatHelper.selectPutChar` will return a `DigitConsumer` instead of a `MethodHandle`.
>
> Currently, you are allocating a new byte array for every number in the format, which I deem very inefficient.
Code based on MethodHandler is difficult to maintain and debug. We should remove the use of MethodHandle in FormatItem.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/15699#issuecomment-1732271564
More information about the core-libs-dev
mailing list