You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2020/07/15 22:35:54 UTC
[lucenenet] 02/06: Lucene.Net.Util.ArrayUtil: Reduced memory
allocations when using GetNaturalComparer() by creating a singleton
instance.
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
commit 6719070fcb008dda88dbb97250fd5144a7d04477
Author: Shad Storhaug <sh...@shadstorhaug.com>
AuthorDate: Thu Jul 16 02:20:24 2020 +0700
Lucene.Net.Util.ArrayUtil: Reduced memory allocations when using GetNaturalComparer<T>() by creating a singleton instance.
---
src/Lucene.Net/Util/ArrayUtil.cs | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/Lucene.Net/Util/ArrayUtil.cs b/src/Lucene.Net/Util/ArrayUtil.cs
index b13b0c0..3931aad 100644
--- a/src/Lucene.Net/Util/ArrayUtil.cs
+++ b/src/Lucene.Net/Util/ArrayUtil.cs
@@ -797,10 +797,12 @@ namespace Lucene.Net.Util
#endif
private class NaturalComparer<T> : IComparer<T> //where T : IComparable<T>
{
- internal NaturalComparer()
+ private NaturalComparer()
{
}
+ public static NaturalComparer<T> Default { get; } = new NaturalComparer<T>();
+
public virtual int Compare(T o1, T o2)
{
return ((IComparable<T>)o1).CompareTo(o2);
@@ -841,7 +843,7 @@ namespace Lucene.Net.Util
// to implement IComparable<T>.
else if (typeof(IComparable<T>).IsAssignableFrom(genericClosingType))
{
- return new NaturalComparer<T>();
+ return NaturalComparer<T>.Default;
}
return Comparer<T>.Default;