Skip to content

Commit

Permalink
Fix more sbyte -> byte conversion remnants, making more tests green
Browse files Browse the repository at this point in the history
  • Loading branch information
synhershko committed Jan 5, 2015
1 parent 4560053 commit 4b6eafe
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,7 @@ private void ReadFields(IndexInput meta, FieldInfos infos)
int fieldType = meta.ReadByte();
if (fieldType == NUMBER)
{
NumericEntry entry = new NumericEntry();
entry.Offset = meta.ReadLong();
entry.Format = meta.ReadSByte();
var entry = new NumericEntry {Offset = meta.ReadLong(), Format = (sbyte)meta.ReadByte()};
switch (entry.Format)
{
case DELTA_COMPRESSED:
Expand Down
12 changes: 3 additions & 9 deletions src/Lucene.Net.Core/Store/DataInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ public abstract class DataInput : ICloneable
/// <seealso cref= DataOutput#writeByte(byte) </seealso>
public abstract byte ReadByte();

public sbyte ReadSByte()
{
// helper method to account for java's byte being signed
return (sbyte)ReadByte();
}

/// <summary>
/// Reads a specified number of bytes into an array at the specified offset. </summary>
/// <param name="b"> the array to read bytes into </param>
Expand Down Expand Up @@ -247,8 +241,8 @@ public virtual long ReadVLong()
/// <seealso cref= DataOutput#writeString(String) </seealso>
public virtual string ReadString()
{
int length = ReadVInt();
byte[] bytes = new byte[length];
var length = ReadVInt();
var bytes = new byte[length];
ReadBytes(bytes, 0, length);

//return new string(bytes, 0, length, IOUtils.CHARSET_UTF_8);
Expand Down Expand Up @@ -323,7 +317,7 @@ public virtual void SkipBytes(long numBytes)
Debug.Assert(SkipBuffer.Length == SKIP_BUFFER_SIZE);
for (long skipped = 0; skipped < numBytes; )
{
int step = (int)Math.Min(SKIP_BUFFER_SIZE, numBytes - skipped);
var step = (int)Math.Min(SKIP_BUFFER_SIZE, numBytes - skipped);
ReadBytes(SkipBuffer, 0, step, false);
skipped += step;
}
Expand Down
16 changes: 8 additions & 8 deletions src/Lucene.Net.Core/Util/Fst/FST.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public FST(DataInput @in, Outputs<T> outputs, int maxBlockBits)
{
emptyOutput = default(T);
}
sbyte t = @in.ReadSByte();
var t = @in.ReadByte();
switch (t)
{
case 0:
Expand Down Expand Up @@ -930,7 +930,7 @@ public Arc<T> ReadLastTargetArc(Arc<T> follow, Arc<T> arc, FST.BytesReader @in)
{
@in.Position = GetNodeAddress(follow.Target);
arc.Node = follow.Target;
sbyte b = @in.ReadSByte();
var b = (sbyte)@in.ReadByte();
if (b == ARCS_AS_FIXED_ARRAY)
{
// array: jump straight to end
Expand Down Expand Up @@ -979,7 +979,7 @@ public Arc<T> ReadLastTargetArc(Arc<T> follow, Arc<T> arc, FST.BytesReader @in)
{
ReadUnpackedNodeTarget(@in);
}
arc.Flags = @in.ReadSByte();
arc.Flags = (sbyte)@in.ReadByte();
}
// Undo the byte flags we read:
@in.SkipBytes(-1);
Expand Down Expand Up @@ -1130,7 +1130,7 @@ public int ReadNextArcLabel(Arc<T> arc, BytesReader @in)
long pos = GetNodeAddress(arc.NextArc);
@in.Position = pos;

sbyte b = @in.ReadSByte();
var b = (sbyte)@in.ReadByte();
if (b == ARCS_AS_FIXED_ARRAY)
{
//System.out.println(" nextArc fixed array");
Expand Down Expand Up @@ -1195,7 +1195,7 @@ public Arc<T> ReadNextRealArc(Arc<T> arc, FST.BytesReader @in)
// arcs are packed
@in.Position = arc.NextArc;
}
arc.Flags = @in.ReadSByte();
arc.Flags = (sbyte)@in.ReadByte();
arc.Label = ReadLabel(@in);

if (arc.Flag(BIT_ARC_HAS_OUTPUT))
Expand Down Expand Up @@ -2166,17 +2166,17 @@ public class FST
internal const sbyte ARCS_AS_FIXED_ARRAY = BIT_ARC_HAS_FINAL_OUTPUT;

/// <summary>
/// <see cref="UnCompiledNode"/>
/// <see cref="Builder{T}.UnCompiledNode{S}"/>
/// </summary>
public const int FIXED_ARRAY_SHALLOW_DISTANCE = 3;

/// <summary>
/// <see cref="UnCompiledNode"/>
/// <see cref="Builder{T}.UnCompiledNode{S}"/>
/// </summary>
public const int FIXED_ARRAY_NUM_ARCS_SHALLOW = 5;

/// <summary>
/// <see cref="UnCompiledNode"/>
/// <see cref="Builder{T}.UnCompiledNode{S}"/>
/// </summary>
public const int FIXED_ARRAY_NUM_ARCS_DEEP = 10;

Expand Down
2 changes: 1 addition & 1 deletion src/Lucene.Net.Core/Util/Fst/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public static IntsRef GetByOutput(FST<long> fst, long targetOutput, FST<long>.By
mid = (int)((uint)(low + high) >> 1);
@in.Position = arc.PosArcsStart;
@in.SkipBytes(arc.BytesPerArc * mid);
sbyte flags = @in.ReadSByte();
var flags = (sbyte)@in.ReadByte();
fst.ReadLabel(@in);
long minArcOutput;
if ((flags & FST<long>.BIT_ARC_HAS_OUTPUT) != 0)
Expand Down
2 changes: 1 addition & 1 deletion src/Lucene.Net.Tests/core/Store/TestCopyBytes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public virtual void TestCopyBytesMem()
{
if (Random().NextBoolean())
{
sbyte v = in2.ReadSByte();
var v = in2.ReadByte();
Assert.AreEqual(Value(upto), v);
upto++;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Lucene.Net.Tests/core/Store/TestHugeRamFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ public virtual void TestHugeFile()
@in.Seek(loc);
for (int i = 0; i < m; i++)
{
sbyte bt = @in.ReadSByte();
sbyte expected = (sbyte)(1 + j + (i & 0x0003F));
var bt = (sbyte)@in.ReadByte();
var expected = (sbyte)(1 + j + (i & 0x0003F));
Assert.AreEqual(expected, bt, "must read same value that was written! j=" + j + " i=" + i);
}
}
Expand Down

0 comments on commit 4b6eafe

Please sign in to comment.