You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2021/02/17 12:13:33 UTC
[lucenenet] 01/05: SWEEP: Removed unnecessary casts to sbyte to
check ranges
This is an automated email from the ASF dual-hosted git repository.
nightowl888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git
commit 453ecb967b86587f6563e9c822d5cf74e99a3404
Author: Shad Storhaug <sh...@shadstorhaug.com>
AuthorDate: Mon Feb 15 23:36:03 2021 +0700
SWEEP: Removed unnecessary casts to sbyte to check ranges
---
.../Taxonomy/DocValuesOrdinalsReader.cs | 2 +-
.../Taxonomy/FastTaxonomyFacetCounts.cs | 2 +-
src/Lucene.Net/Store/BufferedIndexInput.cs | 26 +++++++++++-----------
src/Lucene.Net/Store/ByteArrayDataInput.cs | 26 +++++++++++-----------
src/Lucene.Net/Store/DataInput.cs | 26 +++++++++++-----------
.../Util/Packed/BlockPackedReaderIterator.cs | 16 ++++++-------
6 files changed, 49 insertions(+), 49 deletions(-)
diff --git a/src/Lucene.Net.Facet/Taxonomy/DocValuesOrdinalsReader.cs b/src/Lucene.Net.Facet/Taxonomy/DocValuesOrdinalsReader.cs
index 7621924..6b42aa3 100644
--- a/src/Lucene.Net.Facet/Taxonomy/DocValuesOrdinalsReader.cs
+++ b/src/Lucene.Net.Facet/Taxonomy/DocValuesOrdinalsReader.cs
@@ -109,7 +109,7 @@ namespace Lucene.Net.Facet.Taxonomy
while (offset < upto)
{
byte b = buf.Bytes[offset++];
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
ordinals.Int32s[ordinals.Length] = ((value << 7) | b) + prev;
value = 0;
diff --git a/src/Lucene.Net.Facet/Taxonomy/FastTaxonomyFacetCounts.cs b/src/Lucene.Net.Facet/Taxonomy/FastTaxonomyFacetCounts.cs
index 7c36937..54deaf0 100644
--- a/src/Lucene.Net.Facet/Taxonomy/FastTaxonomyFacetCounts.cs
+++ b/src/Lucene.Net.Facet/Taxonomy/FastTaxonomyFacetCounts.cs
@@ -82,7 +82,7 @@ namespace Lucene.Net.Facet.Taxonomy
while (offset < end)
{
byte b = bytes[offset++];
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
prev = ord = ((ord << 7) | b) + prev;
++m_values[ord];
diff --git a/src/Lucene.Net/Store/BufferedIndexInput.cs b/src/Lucene.Net/Store/BufferedIndexInput.cs
index 716f1c0..6da7586 100644
--- a/src/Lucene.Net/Store/BufferedIndexInput.cs
+++ b/src/Lucene.Net/Store/BufferedIndexInput.cs
@@ -260,26 +260,26 @@ namespace Lucene.Net.Store
if (5 <= (bufferLength - bufferPosition))
{
byte b = m_buffer[bufferPosition++];
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return b;
}
int i = b & 0x7F;
b = m_buffer[bufferPosition++];
i |= (b & 0x7F) << 7;
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return i;
}
b = m_buffer[bufferPosition++];
i |= (b & 0x7F) << 14;
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return i;
}
b = m_buffer[bufferPosition++];
i |= (b & 0x7F) << 21;
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return i;
}
@@ -306,56 +306,56 @@ namespace Lucene.Net.Store
if (9 <= bufferLength - bufferPosition)
{
byte b = m_buffer[bufferPosition++];
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return b;
}
long i = b & 0x7FL;
b = m_buffer[bufferPosition++];
i |= (b & 0x7FL) << 7;
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return i;
}
b = m_buffer[bufferPosition++];
i |= (b & 0x7FL) << 14;
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return i;
}
b = m_buffer[bufferPosition++];
i |= (b & 0x7FL) << 21;
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return i;
}
b = m_buffer[bufferPosition++];
i |= (b & 0x7FL) << 28;
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return i;
}
b = m_buffer[bufferPosition++];
i |= (b & 0x7FL) << 35;
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return i;
}
b = m_buffer[bufferPosition++];
i |= (b & 0x7FL) << 42;
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return i;
}
b = m_buffer[bufferPosition++];
i |= (b & 0x7FL) << 49;
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return i;
}
b = m_buffer[bufferPosition++];
i |= (b & 0x7FL) << 56;
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return i;
}
diff --git a/src/Lucene.Net/Store/ByteArrayDataInput.cs b/src/Lucene.Net/Store/ByteArrayDataInput.cs
index 06d29cc..8fe9220 100644
--- a/src/Lucene.Net/Store/ByteArrayDataInput.cs
+++ b/src/Lucene.Net/Store/ByteArrayDataInput.cs
@@ -123,26 +123,26 @@ namespace Lucene.Net.Store
public override int ReadVInt32()
{
byte b = bytes[pos++];
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return b;
}
int i = b & 0x7F;
b = bytes[pos++];
i |= (b & 0x7F) << 7;
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return i;
}
b = bytes[pos++];
i |= (b & 0x7F) << 14;
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return i;
}
b = bytes[pos++];
i |= (b & 0x7F) << 21;
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return i;
}
@@ -162,56 +162,56 @@ namespace Lucene.Net.Store
public override long ReadVInt64()
{
byte b = bytes[pos++];
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return b;
}
long i = b & 0x7FL;
b = bytes[pos++];
i |= (b & 0x7FL) << 7;
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return i;
}
b = bytes[pos++];
i |= (b & 0x7FL) << 14;
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return i;
}
b = bytes[pos++];
i |= (b & 0x7FL) << 21;
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return i;
}
b = bytes[pos++];
i |= (b & 0x7FL) << 28;
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return i;
}
b = bytes[pos++];
i |= (b & 0x7FL) << 35;
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return i;
}
b = bytes[pos++];
i |= (b & 0x7FL) << 42;
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return i;
}
b = bytes[pos++];
i |= (b & 0x7FL) << 49;
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return i;
}
b = bytes[pos++];
i |= (b & 0x7FL) << 56;
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return i;
}
diff --git a/src/Lucene.Net/Store/DataInput.cs b/src/Lucene.Net/Store/DataInput.cs
index bec94e8..64eabc9 100644
--- a/src/Lucene.Net/Store/DataInput.cs
+++ b/src/Lucene.Net/Store/DataInput.cs
@@ -123,26 +123,26 @@ namespace Lucene.Net.Store
public virtual int ReadVInt32()
{
byte b = ReadByte();
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return b;
}
int i = b & 0x7F;
b = ReadByte();
i |= (b & 0x7F) << 7;
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return i;
}
b = ReadByte();
i |= (b & 0x7F) << 14;
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return i;
}
b = ReadByte();
i |= (b & 0x7F) << 21;
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return i;
}
@@ -191,56 +191,56 @@ namespace Lucene.Net.Store
return i;
*/
byte b = ReadByte();
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return b;
}
long i = b & 0x7FL;
b = ReadByte();
i |= (b & 0x7FL) << 7;
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return i;
}
b = ReadByte();
i |= (b & 0x7FL) << 14;
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return i;
}
b = ReadByte();
i |= (b & 0x7FL) << 21;
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return i;
}
b = ReadByte();
i |= (b & 0x7FL) << 28;
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return i;
}
b = ReadByte();
i |= (b & 0x7FL) << 35;
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return i;
}
b = ReadByte();
i |= (b & 0x7FL) << 42;
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return i;
}
b = ReadByte();
i |= (b & 0x7FL) << 49;
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return i;
}
b = ReadByte();
i |= (b & 0x7FL) << 56;
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return i;
}
diff --git a/src/Lucene.Net/Util/Packed/BlockPackedReaderIterator.cs b/src/Lucene.Net/Util/Packed/BlockPackedReaderIterator.cs
index 1b43ac8..d0b7c49 100644
--- a/src/Lucene.Net/Util/Packed/BlockPackedReaderIterator.cs
+++ b/src/Lucene.Net/Util/Packed/BlockPackedReaderIterator.cs
@@ -48,50 +48,50 @@ namespace Lucene.Net.Util.Packed
internal static long ReadVInt64(DataInput @in)
{
byte b = @in.ReadByte();
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return b;
}
long i = b & 0x7FL;
b = @in.ReadByte();
i |= (b & 0x7FL) << 7;
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return i;
}
b = @in.ReadByte();
i |= (b & 0x7FL) << 14;
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return i;
}
b = @in.ReadByte();
i |= (b & 0x7FL) << 21;
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return i;
}
b = @in.ReadByte();
i |= (b & 0x7FL) << 28;
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return i;
}
b = @in.ReadByte();
i |= (b & 0x7FL) << 35;
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return i;
}
b = @in.ReadByte();
i |= (b & 0x7FL) << 42;
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return i;
}
b = @in.ReadByte();
i |= (b & 0x7FL) << 49;
- if ((sbyte)b >= 0)
+ if (b <= sbyte.MaxValue) // LUCENENET: Optimized equivalent of "if ((sbyte)b >= 0)"
{
return i;
}