On Sun, 10 Mar 2024 20:27:56 GMT, Chen Liang <li...@openjdk.org> wrote:

> Good idea! Since we are now maintaining two code paths, when we update one, 
> we might forget about the other; is it possible to create another interal 
> constructor that takes a `CharSequence`, so we can pass the string in 
> directly, and we pass the `char[]` via `CharBuffer.wrap()`?

Your suggestion could reduce duplicate code, but it would make new 
BigDecimal(char[]) slower. Some programs have already optimized specifically 
for char[], such as:

https://github.com/mysql/mysql-connector-j/blob/release/8.x/src/main/protocol-impl/java/com/mysql/cj/protocol/a/MysqlBinaryValueDecoder.java#L275
 

package com.mysql.cj.protocol.a;
public class MysqlBinaryValueDecoder {
  public <T> T decodeDecimal(byte[] bytes, int offset, int length, 
ValueFactory<T> vf) {
        BigDecimal d = new BigDecimal(StringUtils.toAsciiCharArray(bytes, 
offset, length));
        return vf.createFromBigDecimal(d);
    }
}

-------------

PR Comment: https://git.openjdk.org/jdk/pull/18177#issuecomment-1987461885

Reply via email to