4926314: Optimize Reader.read(CharBuffer)

Reviewed-by: alanb, bpb
This commit is contained in:
Philippe Marschall 2021-04-26 17:33:35 +00:00 committed by Brian Burkhalter
parent 082abbdaf7
commit 65c19c4094
6 changed files with 371 additions and 10 deletions

View file

@ -25,6 +25,7 @@
package java.io;
import java.nio.CharBuffer;
import java.util.Objects;
/**
@ -152,6 +153,23 @@ public class CharArrayReader extends Reader {
}
}
@Override
public int read(CharBuffer target) throws IOException {
synchronized (lock) {
ensureOpen();
if (pos >= count) {
return -1;
}
int avail = count - pos;
int len = Math.min(avail, target.remaining());
target.put(buf, pos, len);
pos += len;
return len;
}
}
/**
* Skips characters. If the stream is already at its end before this method
* is invoked, then no characters are skipped and zero is returned.