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:10 UTC

[34/50] [abbrv] git commit: Fix issue reading VLongs as well

Fix issue reading VLongs as well


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/401752bd
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/401752bd
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/401752bd

Branch: refs/heads/branch_4x
Commit: 401752bd37a3bee89787db23556421bd3b684a3e
Parents: 4c65df0
Author: Paul Irwin <pa...@gmail.com>
Authored: Wed Aug 7 10:00:26 2013 -0400
Committer: Paul Irwin <pa...@gmail.com>
Committed: Wed Aug 7 10:00:26 2013 -0400

----------------------------------------------------------------------
 src/core/Codecs/BlockTreeTermsReader.cs |  2 +-
 src/core/Store/BufferedIndexInput.cs    | 64 +++++++++++++++------------
 src/core/Store/ByteArrayDataInput.cs    | 64 +++++++++++++++------------
 src/core/Store/DataInput.cs             | 66 ++++++++++++++++------------
 4 files changed, 113 insertions(+), 83 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/401752bd/src/core/Codecs/BlockTreeTermsReader.cs
----------------------------------------------------------------------
diff --git a/src/core/Codecs/BlockTreeTermsReader.cs b/src/core/Codecs/BlockTreeTermsReader.cs
index f0148ce..dd73e3d 100644
--- a/src/core/Codecs/BlockTreeTermsReader.cs
+++ b/src/core/Codecs/BlockTreeTermsReader.cs
@@ -3247,7 +3247,7 @@ namespace Lucene.Net.Codecs
                         {
                             parent.term.Grow(termLength);
                         }
-                        Array.Copy(suffixBytes, startBytePos, parent.term.bytes, prefix, suffix);
+                        System.Buffer.BlockCopy(suffixBytes, startBytePos, parent.term.bytes, prefix, suffix);
                     }
                 }
 

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/401752bd/src/core/Store/BufferedIndexInput.cs
----------------------------------------------------------------------
diff --git a/src/core/Store/BufferedIndexInput.cs b/src/core/Store/BufferedIndexInput.cs
index 804ccdd..c701b76 100644
--- a/src/core/Store/BufferedIndexInput.cs
+++ b/src/core/Store/BufferedIndexInput.cs
@@ -259,34 +259,44 @@ namespace Lucene.Net.Store
         {
             if (9 <= bufferLength - bufferPosition)
             {
+                // .NET Port: going back to old style code
                 byte b = buffer[bufferPosition++];
-                if (b >= 0) return b;
-                long i = b & 0x7FL;
-                b = buffer[bufferPosition++];
-                i |= (b & 0x7FL) << 7;
-                if (b >= 0) return i;
-                b = buffer[bufferPosition++];
-                i |= (b & 0x7FL) << 14;
-                if (b >= 0) return i;
-                b = buffer[bufferPosition++];
-                i |= (b & 0x7FL) << 21;
-                if (b >= 0) return i;
-                b = buffer[bufferPosition++];
-                i |= (b & 0x7FL) << 28;
-                if (b >= 0) return i;
-                b = buffer[bufferPosition++];
-                i |= (b & 0x7FL) << 35;
-                if (b >= 0) return i;
-                b = buffer[bufferPosition++];
-                i |= (b & 0x7FL) << 42;
-                if (b >= 0) return i;
-                b = buffer[bufferPosition++];
-                i |= (b & 0x7FL) << 49;
-                if (b >= 0) return i;
-                b = buffer[bufferPosition++];
-                i |= (b & 0x7FL) << 56;
-                if (b >= 0) return i;
-                throw new System.IO.IOException("Invalid vLong detected (negative values disallowed)");
+                long i = b & 0x7F;
+                for (int shift = 7; (b & 0x80) != 0; shift += 7)
+                {
+                    b = buffer[bufferPosition++];
+                    i |= (b & 0x7FL) << shift;
+                }
+                return i;
+
+                //byte b = buffer[bufferPosition++];
+                //if (b >= 0) return b;
+                //long i = b & 0x7FL;
+                //b = buffer[bufferPosition++];
+                //i |= (b & 0x7FL) << 7;
+                //if (b >= 0) return i;
+                //b = buffer[bufferPosition++];
+                //i |= (b & 0x7FL) << 14;
+                //if (b >= 0) return i;
+                //b = buffer[bufferPosition++];
+                //i |= (b & 0x7FL) << 21;
+                //if (b >= 0) return i;
+                //b = buffer[bufferPosition++];
+                //i |= (b & 0x7FL) << 28;
+                //if (b >= 0) return i;
+                //b = buffer[bufferPosition++];
+                //i |= (b & 0x7FL) << 35;
+                //if (b >= 0) return i;
+                //b = buffer[bufferPosition++];
+                //i |= (b & 0x7FL) << 42;
+                //if (b >= 0) return i;
+                //b = buffer[bufferPosition++];
+                //i |= (b & 0x7FL) << 49;
+                //if (b >= 0) return i;
+                //b = buffer[bufferPosition++];
+                //i |= (b & 0x7FL) << 56;
+                //if (b >= 0) return i;
+                //throw new System.IO.IOException("Invalid vLong detected (negative values disallowed)");
             }
             else
             {

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/401752bd/src/core/Store/ByteArrayDataInput.cs
----------------------------------------------------------------------
diff --git a/src/core/Store/ByteArrayDataInput.cs b/src/core/Store/ByteArrayDataInput.cs
index ea36c6b..741f2da 100644
--- a/src/core/Store/ByteArrayDataInput.cs
+++ b/src/core/Store/ByteArrayDataInput.cs
@@ -121,34 +121,44 @@ namespace Lucene.Net.Store
 
         public override long ReadVLong()
         {
+            // .NET Port: going back to old style code
             byte b = bytes[pos++];
-            if (b >= 0) return b;
-            long i = b & 0x7FL;
-            b = bytes[pos++];
-            i |= (b & 0x7FL) << 7;
-            if (b >= 0) return i;
-            b = bytes[pos++];
-            i |= (b & 0x7FL) << 14;
-            if (b >= 0) return i;
-            b = bytes[pos++];
-            i |= (b & 0x7FL) << 21;
-            if (b >= 0) return i;
-            b = bytes[pos++];
-            i |= (b & 0x7FL) << 28;
-            if (b >= 0) return i;
-            b = bytes[pos++];
-            i |= (b & 0x7FL) << 35;
-            if (b >= 0) return i;
-            b = bytes[pos++];
-            i |= (b & 0x7FL) << 42;
-            if (b >= 0) return i;
-            b = bytes[pos++];
-            i |= (b & 0x7FL) << 49;
-            if (b >= 0) return i;
-            b = bytes[pos++];
-            i |= (b & 0x7FL) << 56;
-            if (b >= 0) return i;
-            throw new InvalidOperationException("Invalid vLong detected (negative values disallowed)");
+            long i = b & 0x7F;
+            for (int shift = 7; (b & 0x80) != 0; shift += 7)
+            {
+                b = bytes[pos++];
+                i |= (b & 0x7FL) << shift;
+            }
+            return i;
+
+            //byte b = bytes[pos++];
+            //if (b >= 0) return b;
+            //long i = b & 0x7FL;
+            //b = bytes[pos++];
+            //i |= (b & 0x7FL) << 7;
+            //if (b >= 0) return i;
+            //b = bytes[pos++];
+            //i |= (b & 0x7FL) << 14;
+            //if (b >= 0) return i;
+            //b = bytes[pos++];
+            //i |= (b & 0x7FL) << 21;
+            //if (b >= 0) return i;
+            //b = bytes[pos++];
+            //i |= (b & 0x7FL) << 28;
+            //if (b >= 0) return i;
+            //b = bytes[pos++];
+            //i |= (b & 0x7FL) << 35;
+            //if (b >= 0) return i;
+            //b = bytes[pos++];
+            //i |= (b & 0x7FL) << 42;
+            //if (b >= 0) return i;
+            //b = bytes[pos++];
+            //i |= (b & 0x7FL) << 49;
+            //if (b >= 0) return i;
+            //b = bytes[pos++];
+            //i |= (b & 0x7FL) << 56;
+            //if (b >= 0) return i;
+            //throw new InvalidOperationException("Invalid vLong detected (negative values disallowed)");
         }
 
         public override byte ReadByte()

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/401752bd/src/core/Store/DataInput.cs
----------------------------------------------------------------------
diff --git a/src/core/Store/DataInput.cs b/src/core/Store/DataInput.cs
index 07310a1..3af7802 100644
--- a/src/core/Store/DataInput.cs
+++ b/src/core/Store/DataInput.cs
@@ -97,6 +97,16 @@ namespace Lucene.Net.Store
 
         public virtual long ReadVLong()
         {
+            // .NET Port: going back to old style code
+            byte b = ReadByte();
+            long i = b & 0x7F;
+            for (int shift = 7; (b & 0x80) != 0; shift += 7)
+            {
+                b = ReadByte();
+                i |= (b & 0x7FL) << 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!
@@ -108,34 +118,34 @@ namespace Lucene.Net.Store
             }
             return i;
             */
-            byte b = ReadByte();
-            if (b >= 0) return b;
-            long i = b & 0x7FL;
-            b = ReadByte();
-            i |= (b & 0x7FL) << 7;
-            if (b >= 0) return i;
-            b = ReadByte();
-            i |= (b & 0x7FL) << 14;
-            if (b >= 0) return i;
-            b = ReadByte();
-            i |= (b & 0x7FL) << 21;
-            if (b >= 0) return i;
-            b = ReadByte();
-            i |= (b & 0x7FL) << 28;
-            if (b >= 0) return i;
-            b = ReadByte();
-            i |= (b & 0x7FL) << 35;
-            if (b >= 0) return i;
-            b = ReadByte();
-            i |= (b & 0x7FL) << 42;
-            if (b >= 0) return i;
-            b = ReadByte();
-            i |= (b & 0x7FL) << 49;
-            if (b >= 0) return i;
-            b = ReadByte();
-            i |= (b & 0x7FL) << 56;
-            if (b >= 0) return i;
-            throw new System.IO.IOException("Invalid vLong detected (negative values disallowed)");
+            //byte b = ReadByte();
+            //if (b >= 0) return b;
+            //long i = b & 0x7FL;
+            //b = ReadByte();
+            //i |= (b & 0x7FL) << 7;
+            //if (b >= 0) return i;
+            //b = ReadByte();
+            //i |= (b & 0x7FL) << 14;
+            //if (b >= 0) return i;
+            //b = ReadByte();
+            //i |= (b & 0x7FL) << 21;
+            //if (b >= 0) return i;
+            //b = ReadByte();
+            //i |= (b & 0x7FL) << 28;
+            //if (b >= 0) return i;
+            //b = ReadByte();
+            //i |= (b & 0x7FL) << 35;
+            //if (b >= 0) return i;
+            //b = ReadByte();
+            //i |= (b & 0x7FL) << 42;
+            //if (b >= 0) return i;
+            //b = ReadByte();
+            //i |= (b & 0x7FL) << 49;
+            //if (b >= 0) return i;
+            //b = ReadByte();
+            //i |= (b & 0x7FL) << 56;
+            //if (b >= 0) return i;
+            //throw new System.IO.IOException("Invalid vLong detected (negative values disallowed)");
         }
 
         public virtual string ReadString()