You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by mh...@apache.org on 2013/09/24 20:33:09 UTC
[33/50] [abbrv] git commit: Correct issue with VInts
Correct issue with VInts
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/4c65df01
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/4c65df01
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/4c65df01
Branch: refs/heads/branch_4x
Commit: 4c65df01543ea2da6bcb488362c8cba3db7fff7f
Parents: 37289ca
Author: Paul Irwin <pa...@gmail.com>
Authored: Wed Aug 7 09:37:18 2013 -0400
Committer: Paul Irwin <pa...@gmail.com>
Committed: Wed Aug 7 09:37:18 2013 -0400
----------------------------------------------------------------------
.../Lucene42/Lucene42DocValuesProducer.cs | 5 +--
src/core/Document/Field.cs | 7 +++-
src/core/Index/IIndexableField.cs | 2 +-
src/core/Store/BufferedIndexInput.cs | 40 +++++++++++-------
src/core/Store/ByteArrayDataInput.cs | 42 ++++++++++++-------
src/core/Store/DataInput.cs | 44 ++++++++++++--------
6 files changed, 86 insertions(+), 54 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/4c65df01/src/core/Codecs/Lucene42/Lucene42DocValuesProducer.cs
----------------------------------------------------------------------
diff --git a/src/core/Codecs/Lucene42/Lucene42DocValuesProducer.cs b/src/core/Codecs/Lucene42/Lucene42DocValuesProducer.cs
index 8718010..383a6a5 100644
--- a/src/core/Codecs/Lucene42/Lucene42DocValuesProducer.cs
+++ b/src/core/Codecs/Lucene42/Lucene42DocValuesProducer.cs
@@ -69,9 +69,8 @@ namespace Lucene.Net.Codecs.Lucene42
private void ReadFields(IndexInput meta, FieldInfos infos)
{
int fieldNumber = meta.ReadVInt();
- // TODO: .NET Port: I had to add the != 255 case here for it to work in testing, but that means
- // you can't have more than 255 fields, which seems wrong to me.
- while (fieldNumber != -1 && fieldNumber != 255)
+
+ while (fieldNumber != -1)
{
int fieldType = meta.ReadByte();
if (fieldType == Lucene42DocValuesConsumer.NUMBER)
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/4c65df01/src/core/Document/Field.cs
----------------------------------------------------------------------
diff --git a/src/core/Document/Field.cs b/src/core/Document/Field.cs
index 5ed5585..578680b 100644
--- a/src/core/Document/Field.cs
+++ b/src/core/Document/Field.cs
@@ -346,13 +346,16 @@ namespace Lucene.Net.Documents
}
}
- public long NumericValue
+ public object NumericValue
{
get
{
// .NET Port: No base type for all numeric types, so unless we want to rewrite this
// to be LongValue, IntValue, FloatValue, etc, this will have to do.
- return Convert.ToInt64(fieldsData);
+ if (fieldsData is int || fieldsData is byte || fieldsData is short || fieldsData is long)
+ return Convert.ToInt64(fieldsData);
+
+ return null;
}
}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/4c65df01/src/core/Index/IIndexableField.cs
----------------------------------------------------------------------
diff --git a/src/core/Index/IIndexableField.cs b/src/core/Index/IIndexableField.cs
index f7f12f7..29ff853 100644
--- a/src/core/Index/IIndexableField.cs
+++ b/src/core/Index/IIndexableField.cs
@@ -22,7 +22,7 @@ namespace Lucene.Net.Index
TextReader ReaderValue { get; }
- long NumericValue { get; }
+ object NumericValue { get; }
TokenStream TokenStream(Analyzer analyzer);
}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/4c65df01/src/core/Store/BufferedIndexInput.cs
----------------------------------------------------------------------
diff --git a/src/core/Store/BufferedIndexInput.cs b/src/core/Store/BufferedIndexInput.cs
index 6243a5f..804ccdd 100644
--- a/src/core/Store/BufferedIndexInput.cs
+++ b/src/core/Store/BufferedIndexInput.cs
@@ -221,23 +221,33 @@ namespace Lucene.Net.Store
{
if (5 <= (bufferLength - bufferPosition))
{
+ // .NET Port: going back to original code to avoid sbyte/byte diff
byte b = buffer[bufferPosition++];
- if (b >= 0) return b;
int i = b & 0x7F;
- b = buffer[bufferPosition++];
- i |= (b & 0x7F) << 7;
- if (b >= 0) return i;
- b = buffer[bufferPosition++];
- i |= (b & 0x7F) << 14;
- if (b >= 0) return i;
- b = buffer[bufferPosition++];
- i |= (b & 0x7F) << 21;
- if (b >= 0) return i;
- b = buffer[bufferPosition++];
- // Warning: the next ands use 0x0F / 0xF0 - beware copy/paste errors:
- i |= (b & 0x0F) << 28;
- if ((b & 0xF0) == 0) return i;
- throw new System.IO.IOException("Invalid vInt detected (too many bits)");
+ for (int shift = 7; (b & 0x80) != 0; shift += 7)
+ {
+ b = buffer[bufferPosition++];
+ i |= (b & 0x7F) << shift;
+ }
+ return i;
+
+ //byte b = buffer[bufferPosition++];
+ //if (b >= 0) return b;
+ //int i = b & 0x7F;
+ //b = buffer[bufferPosition++];
+ //i |= (b & 0x7F) << 7;
+ //if (b >= 0) return i;
+ //b = buffer[bufferPosition++];
+ //i |= (b & 0x7F) << 14;
+ //if (b >= 0) return i;
+ //b = buffer[bufferPosition++];
+ //i |= (b & 0x7F) << 21;
+ //if (b >= 0) return i;
+ //b = buffer[bufferPosition++];
+ //// Warning: the next ands use 0x0F / 0xF0 - beware copy/paste errors:
+ //i |= (b & 0x0F) << 28;
+ //if ((b & 0xF0) == 0) return i;
+ //throw new System.IO.IOException("Invalid vInt detected (too many bits)");
}
else
{
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/4c65df01/src/core/Store/ByteArrayDataInput.cs
----------------------------------------------------------------------
diff --git a/src/core/Store/ByteArrayDataInput.cs b/src/core/Store/ByteArrayDataInput.cs
index e865613..ea36c6b 100644
--- a/src/core/Store/ByteArrayDataInput.cs
+++ b/src/core/Store/ByteArrayDataInput.cs
@@ -90,23 +90,33 @@ namespace Lucene.Net.Store
public override int ReadVInt()
{
+ // .NET Port: going back to original style code instead of Java code below due to sbyte/byte diff
byte b = bytes[pos++];
- if (b >= 0) return b;
int i = b & 0x7F;
- b = bytes[pos++];
- i |= (b & 0x7F) << 7;
- if (b >= 0) return i;
- b = bytes[pos++];
- i |= (b & 0x7F) << 14;
- if (b >= 0) return i;
- b = bytes[pos++];
- i |= (b & 0x7F) << 21;
- if (b >= 0) return i;
- b = bytes[pos++];
- // Warning: the next ands use 0x0F / 0xF0 - beware copy/paste errors:
- i |= (b & 0x0F) << 28;
- if ((b & 0xF0) == 0) return i;
- throw new InvalidOperationException("Invalid vInt detected (too many bits)");
+ for (int shift = 7; (b & 0x80) != 0; shift += 7)
+ {
+ b = bytes[pos++];
+ i |= (b & 0x7F) << shift;
+ }
+ return i;
+
+ //byte b = bytes[pos++];
+ //if (b >= 0) return b;
+ //int i = b & 0x7F;
+ //b = bytes[pos++];
+ //i |= (b & 0x7F) << 7;
+ //if (b >= 0) return i;
+ //b = bytes[pos++];
+ //i |= (b & 0x7F) << 14;
+ //if (b >= 0) return i;
+ //b = bytes[pos++];
+ //i |= (b & 0x7F) << 21;
+ //if (b >= 0) return i;
+ //b = bytes[pos++];
+ //// Warning: the next ands use 0x0F / 0xF0 - beware copy/paste errors:
+ //i |= (b & 0x0F) << 28;
+ //if ((b & 0xF0) == 0) return i;
+ //throw new InvalidOperationException("Invalid vInt detected (too many bits)");
}
public override long ReadVLong()
@@ -148,7 +158,7 @@ namespace Lucene.Net.Store
public override void ReadBytes(byte[] b, int offset, int len)
{
- Array.Copy(bytes, pos, b, offset, len);
+ Buffer.BlockCopy(bytes, pos, b, offset, len);
pos += len;
}
}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/4c65df01/src/core/Store/DataInput.cs
----------------------------------------------------------------------
diff --git a/src/core/Store/DataInput.cs b/src/core/Store/DataInput.cs
index 115bd44..07310a1 100644
--- a/src/core/Store/DataInput.cs
+++ b/src/core/Store/DataInput.cs
@@ -50,6 +50,16 @@ namespace Lucene.Net.Store
public virtual int ReadVInt()
{
+ // .NET Port: Going back to original code instead of Java code below due to sbyte/byte diff
+ byte b = ReadByte();
+ int i = b & 0x7F;
+ for (int shift = 7; (b & 0x80) != 0; shift += 7)
+ {
+ b = ReadByte();
+ i |= (b & 0x7F) << shift;
+ }
+ return i;
+
/* This is the original code of this method,
* but a Hotspot bug (see LUCENE-2975) corrupts the for-loop if
* ReadByte() is inlined. So the loop was unwinded!
@@ -61,23 +71,23 @@ namespace Lucene.Net.Store
}
return i;
*/
- byte b = ReadByte();
- if (b >= 0) return b;
- int i = b & 0x7F;
- b = ReadByte();
- i |= (b & 0x7F) << 7;
- if (b >= 0) return i;
- b = ReadByte();
- i |= (b & 0x7F) << 14;
- if (b >= 0) return i;
- b = ReadByte();
- i |= (b & 0x7F) << 21;
- if (b >= 0) return i;
- b = ReadByte();
- // Warning: the next ands use 0x0F / 0xF0 - beware copy/paste errors:
- i |= (b & 0x0F) << 28;
- if ((b & 0xF0) == 0) return i;
- throw new System.IO.IOException("Invalid vInt detected (too many bits)");
+ //byte b = ReadByte();
+ //if (b >= 0) return b;
+ //int i = b & 0x7F;
+ //b = ReadByte();
+ //i |= (b & 0x7F) << 7;
+ //if (b >= 0) return i;
+ //b = ReadByte();
+ //i |= (b & 0x7F) << 14;
+ //if (b >= 0) return i;
+ //b = ReadByte();
+ //i |= (b & 0x7F) << 21;
+ //if (b >= 0) return i;
+ //b = ReadByte();
+ //// Warning: the next ands use 0x0F / 0xF0 - beware copy/paste errors:
+ //i |= (b & 0x0F) << 28;
+ //if ((b & 0xF0) == 0) return i;
+ //throw new System.IO.IOException("Invalid vInt detected (too many bits)");
}
public virtual long ReadLong()