lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [12/50] [abbrv] lucenenet git commit: SWEEP: Lucene.Net.Codecs: Changed all codecs to use long?.GetValueOrDefault() to simplify the logic
Date Sun, 05 Mar 2017 11:48:51 GMT
SWEEP: Lucene.Net.Codecs: Changed all codecs to use long?.GetValueOrDefault() to simplify the
logic


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

Branch: refs/heads/api-work
Commit: ef912b0b810be4becf88303508704431c164934f
Parents: 65c483d
Author: Shad Storhaug <shad@shadstorhaug.com>
Authored: Fri Mar 3 10:18:52 2017 +0700
Committer: Shad Storhaug <shad@shadstorhaug.com>
Committed: Sun Mar 5 17:08:32 2017 +0700

----------------------------------------------------------------------
 .../Memory/DirectDocValuesConsumer.cs                | 12 ++----------
 .../SimpleText/SimpleTextDocValuesWriter.cs          |  2 +-
 .../Codecs/Lucene42/Lucene42NormsConsumer.cs         |  9 ++++-----
 .../Codecs/Lucene45/Lucene45DocValuesConsumer.cs     |  7 +++----
 .../Codecs/Lucene40/Lucene40DocValuesWriter.cs       | 15 +++++++--------
 .../Codecs/Lucene42/Lucene42DocValuesConsumer.cs     | 11 +++++------
 6 files changed, 22 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ef912b0b/src/Lucene.Net.Codecs/Memory/DirectDocValuesConsumer.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Memory/DirectDocValuesConsumer.cs b/src/Lucene.Net.Codecs/Memory/DirectDocValuesConsumer.cs
index 6181139..dea7c28 100644
--- a/src/Lucene.Net.Codecs/Memory/DirectDocValuesConsumer.cs
+++ b/src/Lucene.Net.Codecs/Memory/DirectDocValuesConsumer.cs
@@ -116,7 +116,7 @@ namespace Lucene.Net.Codecs.Memory
             {
                 byteWidth = 1;
             }
-            else if (minValue >= short.MinValue && maxValue <= short.MaxValue)
+            else if (minValue >= short.MinValue && maxValue <= short.MaxValue)
// LUCENENET TODO: Shouldn't this be ushort?
             {
                 byteWidth = 2;
             }
@@ -132,15 +132,7 @@ namespace Lucene.Net.Codecs.Memory
 
             foreach (var nv in values)
             {
-                long v;
-                if (nv != null)
-                {
-                    v = nv.Value;
-                }
-                else
-                {
-                    v = 0;
-                }
+                long v = nv.GetValueOrDefault();
 
                 switch (byteWidth)
                 {

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ef912b0b/src/Lucene.Net.Codecs/SimpleText/SimpleTextDocValuesWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextDocValuesWriter.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextDocValuesWriter.cs
index 8a96be6..e319d6d 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextDocValuesWriter.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextDocValuesWriter.cs
@@ -117,7 +117,7 @@ namespace Lucene.Net.Codecs.SimpleText
             // second pass to write the values
             foreach (var n in values)
             {
-                long value = n == null ? 0 : n.Value;
+                long value = n.GetValueOrDefault();
 
                 Debug.Assert(value >= minValue);
 

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ef912b0b/src/Lucene.Net.Core/Codecs/Lucene42/Lucene42NormsConsumer.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Codecs/Lucene42/Lucene42NormsConsumer.cs b/src/Lucene.Net.Core/Codecs/Lucene42/Lucene42NormsConsumer.cs
index 5a4b7be..794ceaa 100644
--- a/src/Lucene.Net.Core/Codecs/Lucene42/Lucene42NormsConsumer.cs
+++ b/src/Lucene.Net.Core/Codecs/Lucene42/Lucene42NormsConsumer.cs
@@ -139,7 +139,7 @@ namespace Lucene.Net.Codecs.Lucene42
                     meta.WriteByte((byte)UNCOMPRESSED); // uncompressed
                     foreach (long? nv in values)
                     {
-                        data.WriteByte(nv == null ? (byte)0 : (byte)(sbyte)nv.Value);
+                        data.WriteByte((byte)nv.GetValueOrDefault());
                     }
                 }
                 else
@@ -161,7 +161,7 @@ namespace Lucene.Net.Codecs.Lucene42
                     PackedInt32s.Writer writer = PackedInt32s.GetWriterNoHeader(data, formatAndBits.Format,
maxDoc, formatAndBits.BitsPerValue, PackedInt32s.DEFAULT_BUFFER_SIZE);
                     foreach (long? nv in values)
                     {
-                        writer.Add(encode[nv == null ? 0 : nv.Value]);
+                        writer.Add(encode[nv.GetValueOrDefault()]);
                     }
                     writer.Finish();
                 }
@@ -177,8 +177,7 @@ namespace Lucene.Net.Codecs.Lucene42
                 var writer = new BlockPackedWriter(data, BLOCK_SIZE);
                 foreach (long? nv in values)
                 {
-                    long value = nv == null ? 0 : nv.Value;
-                    writer.Add((value - minValue) / gcd);
+                    writer.Add((nv.GetValueOrDefault() - minValue) / gcd);
                 }
                 writer.Finish();
             }
@@ -192,7 +191,7 @@ namespace Lucene.Net.Codecs.Lucene42
                 var writer = new BlockPackedWriter(data, BLOCK_SIZE);
                 foreach (long? nv in values)
                 {
-                    writer.Add(nv == null ? 0 : nv.Value);
+                    writer.Add(nv.GetValueOrDefault());
                 }
                 writer.Finish();
             }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ef912b0b/src/Lucene.Net.Core/Codecs/Lucene45/Lucene45DocValuesConsumer.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Codecs/Lucene45/Lucene45DocValuesConsumer.cs b/src/Lucene.Net.Core/Codecs/Lucene45/Lucene45DocValuesConsumer.cs
index 360d68a..deaa616 100644
--- a/src/Lucene.Net.Core/Codecs/Lucene45/Lucene45DocValuesConsumer.cs
+++ b/src/Lucene.Net.Core/Codecs/Lucene45/Lucene45DocValuesConsumer.cs
@@ -220,8 +220,7 @@ namespace Lucene.Net.Codecs.Lucene45
                     BlockPackedWriter quotientWriter = new BlockPackedWriter(data, BLOCK_SIZE);
                     foreach (long? nv in values)
                     {
-                        long value = nv == null ? 0 : nv.Value;
-                        quotientWriter.Add((value - minValue) / gcd);
+                        quotientWriter.Add((nv.GetValueOrDefault() - minValue) / gcd);
                     }
                     quotientWriter.Finish();
                     break;
@@ -230,7 +229,7 @@ namespace Lucene.Net.Codecs.Lucene45
                     BlockPackedWriter writer = new BlockPackedWriter(data, BLOCK_SIZE);
                     foreach (long? nv in values)
                     {
-                        writer.Add(nv == null ? 0 : nv.Value);
+                        writer.Add(nv.GetValueOrDefault());
                     }
                     writer.Finish();
                     break;
@@ -250,7 +249,7 @@ namespace Lucene.Net.Codecs.Lucene45
                     PackedInt32s.Writer ordsWriter = PackedInt32s.GetWriterNoHeader(data,
PackedInt32s.Format.PACKED, (int)count, bitsRequired, PackedInt32s.DEFAULT_BUFFER_SIZE);
                     foreach (long? nv in values)
                     {
-                        ordsWriter.Add(encode[nv == null ? 0 : nv.Value]);
+                        ordsWriter.Add(encode[nv.GetValueOrDefault()]);
                     }
                     ordsWriter.Finish();
                     break;

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ef912b0b/src/Lucene.Net.TestFramework/Codecs/Lucene40/Lucene40DocValuesWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Codecs/Lucene40/Lucene40DocValuesWriter.cs b/src/Lucene.Net.TestFramework/Codecs/Lucene40/Lucene40DocValuesWriter.cs
index 42856fc..ecb0c69 100644
--- a/src/Lucene.Net.TestFramework/Codecs/Lucene40/Lucene40DocValuesWriter.cs
+++ b/src/Lucene.Net.TestFramework/Codecs/Lucene40/Lucene40DocValuesWriter.cs
@@ -57,7 +57,7 @@ namespace Lucene.Net.Codecs.Lucene40
             long maxValue = long.MinValue;
             foreach (long? n in values)
             {
-                long v = n == null ? 0 : (long)n;
+                long v = n.GetValueOrDefault();
                 minValue = Math.Min(minValue, v);
                 maxValue = Math.Max(maxValue, v);
             }
@@ -72,7 +72,7 @@ namespace Lucene.Net.Codecs.Lucene40
                     // fits in a byte[], would be more than 4bpv, just write byte[]
                     AddBytesField(field, data, values);
                 }
-                else if (minValue >= short.MinValue && maxValue <= short.MaxValue
&& PackedInt32s.BitsRequired(maxValue - minValue) > 8)
+                else if (minValue >= short.MinValue && maxValue <= short.MaxValue
&& PackedInt32s.BitsRequired(maxValue - minValue) > 8) // LUCENENET TODO: Shouldn't
this be ushort.MinValue & MaxValue?
                 {
                     // fits in a short[], would be more than 8bpv, just write short[]
                     AddShortsField(field, data, values);
@@ -108,7 +108,7 @@ namespace Lucene.Net.Codecs.Lucene40
             output.WriteInt32(1); // size
             foreach (long? n in values)
             {
-                output.WriteByte(n == null ? (byte)0 : (byte)n);
+                output.WriteByte((byte)n.GetValueOrDefault());
             }
         }
 
@@ -119,7 +119,7 @@ namespace Lucene.Net.Codecs.Lucene40
             output.WriteInt32(2); // size
             foreach (long? n in values)
             {
-                output.WriteInt16(n == null ? (short)0 : (short)n);
+                output.WriteInt16((short)n.GetValueOrDefault());
             }
         }
 
@@ -130,7 +130,7 @@ namespace Lucene.Net.Codecs.Lucene40
             output.WriteInt32(4); // size
             foreach (long? n in values)
             {
-                output.WriteInt32(n == null ? 0 : (int)n);
+                output.WriteInt32((int)n.GetValueOrDefault());
             }
         }
 
@@ -148,7 +148,7 @@ namespace Lucene.Net.Codecs.Lucene40
                 output.WriteByte((byte)Lucene40DocValuesFormat.VAR_INTS_FIXED_64);
                 foreach (long? n in values)
                 {
-                    output.WriteInt64(n == null ? 0 : n.Value);
+                    output.WriteInt64(n.GetValueOrDefault());
                 }
             }
             else
@@ -160,8 +160,7 @@ namespace Lucene.Net.Codecs.Lucene40
                 PackedInt32s.Writer writer = PackedInt32s.GetWriter(output, State.SegmentInfo.DocCount,
PackedInt32s.BitsRequired(delta), PackedInt32s.DEFAULT);
                 foreach (long? n in values)
                 {
-                    long v = n == null ? 0 : (long)n;
-                    writer.Add(v - minValue);
+                    writer.Add(n.GetValueOrDefault() - minValue);
                 }
                 writer.Finish();
             }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ef912b0b/src/Lucene.Net.TestFramework/Codecs/Lucene42/Lucene42DocValuesConsumer.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Codecs/Lucene42/Lucene42DocValuesConsumer.cs b/src/Lucene.Net.TestFramework/Codecs/Lucene42/Lucene42DocValuesConsumer.cs
index 7441346..8379e72 100644
--- a/src/Lucene.Net.TestFramework/Codecs/Lucene42/Lucene42DocValuesConsumer.cs
+++ b/src/Lucene.Net.TestFramework/Codecs/Lucene42/Lucene42DocValuesConsumer.cs
@@ -103,7 +103,7 @@ namespace Lucene.Net.Codecs.Lucene42
                 foreach (long? nv in values)
                 {
                     // TODO: support this as MemoryDVFormat (and be smart about missing maybe)
-                    long v = nv == null ? 0 : (long)nv;
+                    long v = nv.GetValueOrDefault();
 
                     if (gcd != 1)
                     {
@@ -149,7 +149,7 @@ namespace Lucene.Net.Codecs.Lucene42
                     Meta.WriteByte((byte)Lucene42DocValuesProducer.UNCOMPRESSED); // uncompressed
                     foreach (long? nv in values)
                     {
-                        Data.WriteByte(nv == null ? (byte)0 : (byte)nv);
+                        Data.WriteByte((byte)nv.GetValueOrDefault());
                     }
                 }
                 else
@@ -171,7 +171,7 @@ namespace Lucene.Net.Codecs.Lucene42
                     PackedInt32s.Writer writer = PackedInt32s.GetWriterNoHeader(Data, formatAndBits.Format,
MaxDoc, formatAndBits.BitsPerValue, PackedInt32s.DEFAULT_BUFFER_SIZE);
                     foreach (long? nv in values)
                     {
-                        writer.Add(encode[nv == null ? 0 : (long)nv]);
+                        writer.Add(encode[nv.GetValueOrDefault()]);
                     }
                     writer.Finish();
                 }
@@ -187,8 +187,7 @@ namespace Lucene.Net.Codecs.Lucene42
                 BlockPackedWriter writer = new BlockPackedWriter(Data, Lucene42DocValuesProducer.BLOCK_SIZE);
                 foreach (long? nv in values)
                 {
-                    long value = nv == null ? 0 : (long)nv;
-                    writer.Add((value - minValue) / gcd);
+                    writer.Add((nv.GetValueOrDefault() - minValue) / gcd);
                 }
                 writer.Finish();
             }
@@ -202,7 +201,7 @@ namespace Lucene.Net.Codecs.Lucene42
                 BlockPackedWriter writer = new BlockPackedWriter(Data, Lucene42DocValuesProducer.BLOCK_SIZE);
                 foreach (long? nv in values)
                 {
-                    writer.Add(nv == null ? 0 : (long)nv);
+                    writer.Add(nv.GetValueOrDefault());
                 }
                 writer.Finish();
             }


Mime
View raw message