提交 1cab2114 authored 作者: Thomas Mueller's avatar Thomas Mueller

Use 16 KB less memory.

上级 5de35fa8
......@@ -87,13 +87,16 @@ public class SecureFileStore extends FileStore {
long length = length();
if (newLength > length) {
seek(length);
byte[] empty = EMPTY;
if (empty == null) {
empty = new byte[16 * 1024];
}
byte[] e = empty;
while (true) {
int p = (int) Math.min(newLength - length, EMPTY.length);
int p = (int) Math.min(newLength - length, e.length);
if (p <= 0) {
break;
}
write(empty, 0, p);
write(e, 0, p);
length += p;
}
seek(oldPos);
......
......@@ -34,7 +34,7 @@ public class FileStore {
* An empty buffer to speed up extending the file (it seems that writing 0
* bytes is faster then calling setLength).
*/
protected static final byte[] EMPTY = new byte[16 * 1024];
protected static byte[] empty;
/**
* The magic file header.
......@@ -356,13 +356,16 @@ public class FileStore {
private void extendByWriting(long newLength) throws IOException {
long pos = filePos;
file.seek(fileLength);
byte[] empty = EMPTY;
if (empty == null) {
empty = new byte[16 * 1024];
}
byte[] e = empty;
while (true) {
int p = (int) Math.min(newLength - fileLength, EMPTY.length);
int p = (int) Math.min(newLength - fileLength, e.length);
if (p <= 0) {
break;
}
file.write(empty, 0, p);
file.write(e, 0, p);
fileLength += p;
}
file.seek(pos);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论