Fix compilation issues and buffer expansions

This commit is contained in:
Andrea Cavalli 2021-09-03 16:11:14 +02:00
parent 47de651c94
commit 154086dee2
4 changed files with 26 additions and 8 deletions

View File

@ -660,7 +660,7 @@ public class LLLocalDictionary implements LLDictionary {
prevData = null;
}
} else {
var obtainedPrevData = dbGet(cfh, null, key.send(), existsAlmostCertainly);
var obtainedPrevData = dbGet(cfh, null, key.copy().send(), existsAlmostCertainly);
if (obtainedPrevData == null) {
prevData = null;
} else {

View File

@ -96,10 +96,10 @@ public class BufferDataInput implements DataInput, SafeCloseable {
@Override
public String readUTF() {
var len = buf.readUnsignedShort();
try (var copiedBuf = buf.copy(buf.readerOffset(), len)) {
var off = copiedBuf.readerOffset();
return LLUtils.deserializeString(copiedBuf.send(), off, len, StandardCharsets.UTF_8);
}
byte[] bytes = new byte[len];
buf.copyInto(buf.readerOffset(), bytes, 0, len);
buf.readerOffset(buf.readerOffset() + len);
return new String(bytes, StandardCharsets.UTF_8);
}
@Override

View File

@ -19,72 +19,90 @@ public class BufferDataOutput implements DataOutput {
@Override
public void write(int b) {
buf.ensureWritable(Integer.BYTES);
buf.writeUnsignedByte(b);
}
@Override
public void write(byte @NotNull [] b) {
buf.ensureWritable(Byte.BYTES * b.length);
buf.writeBytes(b);
}
@Override
public void write(byte @NotNull [] b, int off, int len) {
buf.ensureWritable(len);
buf.writeBytes(b, off, len);
}
@Override
public void writeBoolean(boolean v) {
buf.ensureWritable(Byte.BYTES);
buf.writeUnsignedByte(v ? 1 : 0);
}
@Override
public void writeByte(int v) {
buf.ensureWritable(Byte.BYTES);
buf.writeByte((byte) v);
}
@Override
public void writeShort(int v) {
buf.ensureWritable(Short.BYTES);
buf.writeShort((short) v);
}
@Override
public void writeChar(int v) {
buf.ensureWritable(Character.BYTES);
buf.writeChar((char) v);
}
@Override
public void writeInt(int v) {
buf.ensureWritable(Integer.BYTES);
buf.writeInt(v);
}
@Override
public void writeLong(long v) {
buf.ensureWritable(Long.BYTES);
buf.writeLong(v);
}
@Override
public void writeFloat(float v) {
buf.ensureWritable(Float.BYTES);
buf.writeFloat(v);
}
@Override
public void writeDouble(double v) {
buf.ensureWritable(Double.BYTES);
buf.writeDouble(v);
}
@Override
public void writeBytes(@NotNull String s) {
buf.writeBytes(s.getBytes());
var b= s.getBytes(StandardCharsets.UTF_8);
buf.ensureWritable(Byte.BYTES * b.length);
buf.writeBytes(b);
}
@Override
public void writeChars(@NotNull String s) {
s.chars().forEach(c -> buf.writeChar((char) c));
var chars = s.toCharArray();
buf.ensureWritable(Character.BYTES * chars.length);
for (char c : chars) {
buf.writeChar(c);
}
}
@Override
public void writeUTF(@NotNull String s) {
var bytes = s.getBytes(StandardCharsets.UTF_8);
buf.ensureWritable(Short.BYTES + Byte.BYTES * bytes.length);
buf.writeUnsignedShort(bytes.length);
buf.writeBytes(bytes);
}

View File

@ -75,7 +75,7 @@ public class RandomFieldComparator extends FieldComparator<Float> implements Lea
}
};
if (!(scorer instanceof ScoreCachingWrappingScorer)) {
this.scorer = ScoreCachingWrappingScorer.wrap(randomizedScorer);
this.scorer = new ScoreCachingWrappingScorer(randomizedScorer);
} else {
this.scorer = randomizedScorer;
}