8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char

Reviewed-by: alanb, redestad
This commit is contained in:
Brian Burkhalter 2019-02-22 10:13:33 -08:00
parent 98ebd2bc9e
commit b24f8ba2ec
2 changed files with 85 additions and 0 deletions

View file

@ -270,6 +270,25 @@ class Heap$Type$Buffer$RW$
#end[rw]
}
#if[char]
public $Type$Buffer put(String src, int start, int end) {
int length = end - start;
checkBounds(start, length, src.length());
if (isReadOnly())
throw new ReadOnlyBufferException();
int pos = position();
int lim = limit();
int rem = (pos <= lim) ? lim - pos : 0;
if (length > rem)
throw new BufferOverflowException();
src.getChars(start, end, hb, ix(pos));
position(pos + length);
return this;
}
#end[char]
public $Type$Buffer compact() {
#if[rw]
System.arraycopy(hb, ix(position()), hb, ix(0), remaining());