Remove buggy optimization in DirectBytesBuffer #58

This commit is contained in:
leventov
2015-11-17 15:00:01 +03:00
parent fdc3720e29
commit 6b7eb99144
2 changed files with 176 additions and 32 deletions
@@ -90,25 +90,23 @@ class DirectBytesBuffer
}
void init(M writer, E e, boolean mutable, long maxSize, boolean checked) {
if (mutable || writer != this.writer || e != cur) {
this.writer = writer;
cur = e;
while (true) {
try {
Bytes buffer = this.buffer.obtain(maxSize, true);
if (checked)
buffer = new BoundsCheckingDirectBytes(buffer, null);
writer.write(buffer, e);
buffer.flip();
long size = this.size = buffer.remaining();
this.buffer.buffer.position(0L);
this.buffer.buffer.limit(size);
hash = 0L;
return;
} catch (Exception ex) {
checkMaxSizeStillReasonable(maxSize, ex);
maxSize *= 2L;
}
this.writer = writer;
cur = e;
while (true) {
try {
Bytes buffer = this.buffer.obtain(maxSize, true);
if (checked)
buffer = new BoundsCheckingDirectBytes(buffer, null);
writer.write(buffer, e);
buffer.flip();
long size = this.size = buffer.remaining();
this.buffer.buffer.position(0L);
this.buffer.buffer.limit(size);
hash = 0L;
return;
} catch (Exception ex) {
checkMaxSizeStillReasonable(maxSize, ex);
maxSize *= 2L;
}
}
}
@@ -123,19 +121,17 @@ class DirectBytesBuffer
}
void init(W writer, E e, boolean mutable, boolean checked) {
if (mutable || writer != this.writer || e != cur) {
this.writer = writer;
cur = e;
long size = writer.size(e);
Bytes buffer = this.buffer.obtain(size, true);
if (checked)
buffer = new BoundsCheckingDirectBytes(buffer, null);
writer.write(buffer, e);
buffer.flip();
this.size = size;
assert size == buffer.remaining();
hash = 0L;
}
this.writer = writer;
cur = e;
long size = writer.size(e);
Bytes buffer = this.buffer.obtain(size, true);
if (checked)
buffer = new BoundsCheckingDirectBytes(buffer, null);
writer.write(buffer, e);
buffer.flip();
this.size = size;
assert size == buffer.remaining();
hash = 0L;
}
}