Lucene.Net.Core.Codecs.Lucene42: Fixed subtle performance and other issues that 
may result in random test failures.


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

Branch: refs/heads/api-work
Commit: 046b812853b85fcfaf29347156a630718b053822
Parents: cc71ddb
Author: Shad Storhaug <[email protected]>
Authored: Thu Mar 9 00:59:41 2017 +0700
Committer: Shad Storhaug <[email protected]>
Committed: Thu Mar 9 01:11:08 2017 +0700

----------------------------------------------------------------------
 .../Lucene42/Lucene42DocValuesProducer.cs       | 31 ++++++++++----------
 .../Codecs/Lucene42/Lucene42FieldInfosReader.cs | 11 ++++---
 2 files changed, 23 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/046b8128/src/Lucene.Net.Core/Codecs/Lucene42/Lucene42DocValuesProducer.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Codecs/Lucene42/Lucene42DocValuesProducer.cs 
b/src/Lucene.Net.Core/Codecs/Lucene42/Lucene42DocValuesProducer.cs
index 7205c24..dde3fdf 100644
--- a/src/Lucene.Net.Core/Codecs/Lucene42/Lucene42DocValuesProducer.cs
+++ b/src/Lucene.Net.Core/Codecs/Lucene42/Lucene42DocValuesProducer.cs
@@ -170,7 +170,9 @@ namespace Lucene.Net.Codecs.Lucene42
                 int fieldType = meta.ReadByte();
                 if (fieldType == NUMBER)
                 {
-                    var entry = new NumericEntry {Offset = meta.ReadInt64(), 
Format = (sbyte)meta.ReadByte()};
+                    var entry = new NumericEntry();
+                    entry.Offset = meta.ReadInt64();
+                    entry.Format = (sbyte)meta.ReadByte();
                     switch (entry.Format)
                     {
                         case DELTA_COMPRESSED:
@@ -222,8 +224,7 @@ namespace Lucene.Net.Codecs.Lucene42
             lock (this)
             {
                 NumericDocValues instance;
-                numericInstances.TryGetValue(field.Number, out instance);
-                if (instance == null)
+                if (!numericInstances.TryGetValue(field.Number, out instance) 
|| instance == null)
                 {
                     instance = LoadNumeric(field);
                     numericInstances[field.Number] = instance;
@@ -289,7 +290,7 @@ namespace Lucene.Net.Codecs.Lucene42
                     return new NumericDocValuesAnonymousInnerClassHelper3(min, 
mult, quotientReader);
 
                 default:
-                    throw new InvalidOperationException();
+                    throw new InvalidOperationException(); // LUCENENET TODO: 
This was AssertionError in Lucene - does this need a fix?
             }
         }
 
@@ -349,7 +350,7 @@ namespace Lucene.Net.Codecs.Lucene42
             lock (this)
             {
                 BinaryDocValues instance;
-                if (!binaryInstances.TryGetValue(field.Number, out instance))
+                if (!binaryInstances.TryGetValue(field.Number, out instance) 
|| instance == null)
                 {
                     instance = LoadBinary(field);
                     binaryInstances[field.Number] = instance;
@@ -421,7 +422,7 @@ namespace Lucene.Net.Codecs.Lucene42
             FST<long?> instance;
             lock (this)
             {
-                if (!fstInstances.TryGetValue(field.Number, out instance))
+                if (!fstInstances.TryGetValue(field.Number, out instance) || 
instance == null)
                 {
                     data.Seek(entry.Offset);
                     instance = new FST<long?>(data, 
PositiveInt32Outputs.Singleton);
@@ -484,7 +485,7 @@ namespace Lucene.Net.Codecs.Lucene42
                 }
                 catch (System.IO.IOException bogus)
                 {
-                    throw bogus;
+                    throw new Exception(bogus.ToString(), bogus);
                 }
             }
 
@@ -499,16 +500,16 @@ namespace Lucene.Net.Codecs.Lucene42
                     }
                     else if (o.Input.Equals(key))
                     {
-                        return (int)o.Output;
+                        return (int)o.Output.GetValueOrDefault();
                     }
                     else
                     {
-                        return (int)-o.Output - 1;
+                        return (int)-o.Output.GetValueOrDefault() - 1;
                     }
                 }
                 catch (System.IO.IOException bogus)
                 {
-                    throw bogus;
+                    throw new Exception(bogus.ToString(), bogus);
                 }
             }
 
@@ -536,10 +537,10 @@ namespace Lucene.Net.Codecs.Lucene42
             FST<long?> instance;
             lock (this)
             {
-                if (!fstInstances.TryGetValue(field.Number, out instance))
+                if (!fstInstances.TryGetValue(field.Number, out instance) || 
instance == null)
                 {
                     data.Seek(entry.Offset);
-                    instance = new FST<long?>((DataInput)data, 
Lucene.Net.Util.Fst.PositiveInt32Outputs.Singleton);
+                    instance = new FST<long?>(data, 
PositiveInt32Outputs.Singleton);
                     ramBytesUsed.AddAndGet(instance.SizeInBytes());
                     fstInstances[field.Number] = instance;
                 }
@@ -636,11 +637,11 @@ namespace Lucene.Net.Codecs.Lucene42
                     }
                     else if (o.Input.Equals(key))
                     {
-                        return (int)o.Output.Value;
+                        return (int)o.Output.GetValueOrDefault();
                     }
                     else
                     {
-                        return -o.Output.Value - 1;
+                        return -o.Output.GetValueOrDefault() - 1;
                     }
                 }
                 catch (System.IO.IOException bogus)
@@ -809,7 +810,7 @@ namespace Lucene.Net.Codecs.Lucene42
 
             public override long Ord
             {
-                get { return @in.Current.Output.Value; }
+                get { return @in.Current.Output.GetValueOrDefault(); }
             }
 
             public override int DocFreq

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/046b8128/src/Lucene.Net.Core/Codecs/Lucene42/Lucene42FieldInfosReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Codecs/Lucene42/Lucene42FieldInfosReader.cs 
b/src/Lucene.Net.Core/Codecs/Lucene42/Lucene42FieldInfosReader.cs
index b663a87..b50c075 100644
--- a/src/Lucene.Net.Core/Codecs/Lucene42/Lucene42FieldInfosReader.cs
+++ b/src/Lucene.Net.Core/Codecs/Lucene42/Lucene42FieldInfosReader.cs
@@ -55,7 +55,9 @@ namespace Lucene.Net.Codecs.Lucene42
             bool success = false;
             try
             {
-                CodecUtil.CheckHeader(input, 
Lucene42FieldInfosFormat.CODEC_NAME, Lucene42FieldInfosFormat.FORMAT_START, 
Lucene42FieldInfosFormat.FORMAT_CURRENT);
+                CodecUtil.CheckHeader(input, 
Lucene42FieldInfosFormat.CODEC_NAME, 
+                                            
Lucene42FieldInfosFormat.FORMAT_START, 
+                                            
Lucene42FieldInfosFormat.FORMAT_CURRENT);
 
                 int size = input.ReadVInt32(); //read in the size
                 FieldInfo[] infos = new FieldInfo[size];
@@ -64,7 +66,7 @@ namespace Lucene.Net.Codecs.Lucene42
                 {
                     string name = input.ReadString();
                     int fieldNumber = input.ReadVInt32();
-                    byte bits = input.ReadByte();
+                    sbyte bits = (sbyte)input.ReadByte();
                     bool isIndexed = (bits & 
Lucene42FieldInfosFormat.IS_INDEXED) != 0;
                     bool storeTermVector = (bits & 
Lucene42FieldInfosFormat.STORE_TERMVECTOR) != 0;
                     bool omitNorms = (bits & 
Lucene42FieldInfosFormat.OMIT_NORMS) != 0;
@@ -92,11 +94,12 @@ namespace Lucene.Net.Codecs.Lucene42
                     }
 
                     // DV Types are packed in one byte
-                    byte val = input.ReadByte();
+                    sbyte val = (sbyte)input.ReadByte();
                     DocValuesType? docValuesType = GetDocValuesType(input, 
(sbyte)(val & 0x0F));
                     DocValuesType? normsType = GetDocValuesType(input, 
(sbyte)(((int)((uint)val >> 4)) & 0x0F));
                     IDictionary<string, string> attributes = 
input.ReadStringStringMap();
-                    infos[i] = new FieldInfo(name, isIndexed, fieldNumber, 
storeTermVector, omitNorms, storePayloads, indexOptions, docValuesType, 
normsType, Collections.UnmodifiableMap(attributes));
+                    infos[i] = new FieldInfo(name, isIndexed, fieldNumber, 
storeTermVector, 
+                        omitNorms, storePayloads, indexOptions, docValuesType, 
normsType, Collections.UnmodifiableMap(attributes));
                 }
 
                 CodecUtil.CheckEOF(input);

Reply via email to