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


The following commit(s) were added to refs/heads/master by this push:
     new 18e84c1  PERFORAMANCE: Lucene.Net.Search.FieldCacheRangeFilter: Added 
protected Equals(x, y) method to allow subclasses to compare equality for value 
types without boxing
18e84c1 is described below

commit 18e84c1677ab2613b9911e9db3ca08fdf537ae24
Author: Shad Storhaug <[email protected]>
AuthorDate: Mon Dec 20 21:22:55 2021 +0700

    PERFORAMANCE: Lucene.Net.Search.FieldCacheRangeFilter: Added protected 
Equals(x, y) method to allow subclasses to compare equality for value types 
without boxing
---
 src/Lucene.Net/Search/FieldCacheRangeFilter.cs | 61 +++++++++++++++++++++++++-
 1 file changed, 59 insertions(+), 2 deletions(-)

diff --git a/src/Lucene.Net/Search/FieldCacheRangeFilter.cs 
b/src/Lucene.Net/Search/FieldCacheRangeFilter.cs
index df6b43b..8be0d22 100644
--- a/src/Lucene.Net/Search/FieldCacheRangeFilter.cs
+++ b/src/Lucene.Net/Search/FieldCacheRangeFilter.cs
@@ -2,6 +2,7 @@
 using Lucene.Net.Diagnostics;
 using System;
 using System.Text;
+using JCG = J2N.Collections.Generic;
 
 namespace Lucene.Net.Search
 {
@@ -244,6 +245,14 @@ namespace Lucene.Net.Search
                     return value >= inclusiveLowerPoint && value <= 
inclusiveUpperPoint;
                 });
             }
+
+            // LUCENENET specific - since we use value types, we need to use 
special handling to avoid boxing.
+            protected override bool Equals(sbyte? objA, sbyte? objB)
+            {
+                if (!objA.HasValue) return !objB.HasValue;
+                else if (!objB.HasValue) return false;
+                return JCG.EqualityComparer<sbyte>.Default.Equals(objA.Value, 
objB.Value);
+            }
         }
 
         private class Int16FieldCacheRangeFilterAnonymousClass : 
FieldCacheRangeFilter<short?>
@@ -294,6 +303,14 @@ namespace Lucene.Net.Search
                     return value >= inclusiveLowerPoint && value <= 
inclusiveUpperPoint;
                 });
             }
+
+            // LUCENENET specific - since we use value types, we need to use 
special handling to avoid boxing.
+            protected override bool Equals(short? objA, short? objB)
+            {
+                if (!objA.HasValue) return !objB.HasValue;
+                else if (!objB.HasValue) return false;
+                return JCG.EqualityComparer<short>.Default.Equals(objA.Value, 
objB.Value);
+            }
         }
 
         private class Int32FieldCacheRangeFilterAnonymousClass : 
FieldCacheRangeFilter<int?>
@@ -341,6 +358,14 @@ namespace Lucene.Net.Search
                     return value >= inclusiveLowerPoint && value <= 
inclusiveUpperPoint;
                 });
             }
+
+            // LUCENENET specific - since we use value types, we need to use 
special handling to avoid boxing.
+            protected override bool Equals(int? objA, int? objB)
+            {
+                if (!objA.HasValue) return !objB.HasValue;
+                else if (!objB.HasValue) return false;
+                return JCG.EqualityComparer<int>.Default.Equals(objA.Value, 
objB.Value);
+            }
         }
 
         private class Int64FieldCacheRangeFilterAnonymousClass : 
FieldCacheRangeFilter<long?>
@@ -388,6 +413,14 @@ namespace Lucene.Net.Search
                     return value >= inclusiveLowerPoint && value <= 
inclusiveUpperPoint;
                 });
             }
+
+            // LUCENENET specific - since we use value types, we need to use 
special handling to avoid boxing.
+            protected override bool Equals(long? objA, long? objB)
+            {
+                if (!objA.HasValue) return !objB.HasValue;
+                else if (!objB.HasValue) return false;
+                return JCG.EqualityComparer<long>.Default.Equals(objA.Value, 
objB.Value);
+            }
         }
 
         private class SingleFieldCacheRangeFilterAnonymousClass : 
FieldCacheRangeFilter<float?>
@@ -440,6 +473,14 @@ namespace Lucene.Net.Search
                     return value >= inclusiveLowerPoint && value <= 
inclusiveUpperPoint;
                 });
             }
+
+            // LUCENENET specific - since we use value types, we need to use 
special handling to avoid boxing.
+            protected override bool Equals(float? objA, float? objB)
+            {
+                if (!objA.HasValue) return !objB.HasValue;
+                else if (!objB.HasValue) return false;
+                return JCG.EqualityComparer<float>.Default.Equals(objA.Value, 
objB.Value);
+            }
         }
 
         private class DoubleFieldCacheRangeFilterAnonymousClass : 
FieldCacheRangeFilter<double?>
@@ -492,6 +533,14 @@ namespace Lucene.Net.Search
                     return value >= inclusiveLowerPoint && value <= 
inclusiveUpperPoint;
                 });
             }
+
+            // LUCENENET specific - since we use value types, we need to use 
special handling to avoid boxing.
+            protected override bool Equals(double? objA, double? objB)
+            {
+                if (!objA.HasValue) return !objB.HasValue;
+                else if (!objB.HasValue) return false;
+                return JCG.EqualityComparer<double>.Default.Equals(objA.Value, 
objB.Value);
+            }
         }
 
         //The functions (Starting on line 84 in Lucene)
@@ -704,11 +753,13 @@ namespace Lucene.Net.Search
             {
                 return false;
             }
-            if (this.lowerVal != null ? !this.lowerVal.Equals(other.lowerVal) 
: other.lowerVal != null)
+            // LUCENENET specific - since we use value types, we need to use 
special handling to avoid boxing.
+            if (!Equals(this.lowerVal, other.lowerVal))
             {
                 return false;
             }
-            if (this.upperVal != null ? !this.upperVal.Equals(other.upperVal) 
: other.upperVal != null)
+            // LUCENENET specific - since we use value types, we need to use 
special handling to avoid boxing.
+            if (!Equals(this.upperVal, other.upperVal))
             {
                 return false;
             }
@@ -718,6 +769,12 @@ namespace Lucene.Net.Search
             }
             return true;
         }
+        
+        // LUCENENET specific - override this method to eliminate boxing on 
value types
+        protected virtual bool Equals(T objA, T objB)
+        {
+            return objA != null ? objA.Equals(objB) : objB != null;
+        }
 
         public override sealed int GetHashCode()
         {

Reply via email to