提交 dadfe1d7 authored 作者: Thomas Mueller's avatar Thomas Mueller

Small performance improvement.

上级 bd49396b
...@@ -1014,14 +1014,19 @@ public class Data { ...@@ -1014,14 +1014,19 @@ public class Data {
*/ */
public void checkCapacity(int plus) { public void checkCapacity(int plus) {
if (pos + plus >= data.length) { if (pos + plus >= data.length) {
byte[] d = Utils.newBytes((data.length + plus) * 2); // a separate method to simplify inlining
// must copy everything, because pos could be 0 and data may be expand(plus);
// still required
System.arraycopy(data, 0, d, 0, data.length);
data = d;
} }
} }
private void expand(int plus) {
byte[] d = Utils.newBytes((data.length + plus) * 2);
// must copy everything, because pos could be 0 and data may be
// still required
System.arraycopy(data, 0, d, 0, data.length);
data = d;
}
/** /**
* Fill up the buffer with empty space and an (initially empty) checksum * Fill up the buffer with empty space and an (initially empty) checksum
* until the size is a multiple of Constants.FILE_BLOCK_SIZE. * until the size is a multiple of Constants.FILE_BLOCK_SIZE.
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论