RFR: 8305811: (bf) Improve heap buffer performance of CharBuffer::append(CharSequence) [v2]

Brian Burkhalter bpb at openjdk.org
Thu Apr 13 15:45:10 UTC 2023


On Thu, 13 Apr 2023 07:01:29 GMT, Alan Bateman <alanb at openjdk.org> wrote:

>> Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   8305811: Refactor append methods
>
> src/java.base/share/classes/java/nio/Heap-X-Buffer.java.template line 293:
> 
>> 291:         int pos = position();
>> 292:         if (length > limit() - pos)
>> 293:             throw new BufferOverflowException();
> 
> I think it would be safer to compute the remaining, as `int rem = (pos <= lim) ? lim - pos : 0;` to avoid needing to re-audit this code in the future.

As we did before. I should have caught that. Fixed in d980ce22f02b6c7e0b3ac071f5fb7bc81d4481ed.

> src/java.base/share/classes/java/nio/Heap-X-Buffer.java.template line 313:
> 
>> 311:     public $Type$Buffer append(CharSequence csq, int start, int end) {
>> 312: #if[rw]
>> 313:         if (csq instanceof StringBuilder strbld)
> 
> Given the naming CharBuffer cb, CharSequence csq, heap buffer hb, then "StringBuilder sb" would keep it consistent.

Fixed in d980ce22f02b6c7e0b3ac071f5fb7bc81d4481ed.

> src/java.base/share/classes/java/nio/X-Buffer.java.template line 2047:
> 
>> 2045:      */
>> 2046:     public $Type$Buffer append(CharSequence csq, int start, int end) {
>> 2047:         CharSequence cs = (csq == null ? "null" : csq);
> 
> cs is not used when csq is a CharBuffer so you can probably move this line down to 2055.

So changed in d980ce22f02b6c7e0b3ac071f5fb7bc81d4481ed.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/13415#discussion_r1165718267
PR Review Comment: https://git.openjdk.org/jdk/pull/13415#discussion_r1165717668
PR Review Comment: https://git.openjdk.org/jdk/pull/13415#discussion_r1165718563


More information about the nio-dev mailing list