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/06/30 21:51:02 UTC
[lucenenet] 26/27: Lucene.Net.Util: Use Array.Empty() when
possible
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 80abcf86fda050602e26132f0d78d7d0d7643733
Author: Shad Storhaug <sh...@shadstorhaug.com>
AuthorDate: Wed Jul 1 01:21:59 2020 +0700
Lucene.Net.Util: Use Array.Empty<T>() when possible
---
src/Lucene.Net/Util/Bits.cs | 10 ++++++++--
src/Lucene.Net/Util/BytesRef.cs | 7 ++++++-
src/Lucene.Net/Util/CharsRef.cs | 8 ++++++--
src/Lucene.Net/Util/FieldCacheSanityChecker.cs | 4 ++++
src/Lucene.Net/Util/Fst/FST.cs | 7 ++++++-
src/Lucene.Net/Util/IntsRef.cs | 7 ++++++-
src/Lucene.Net/Util/LongsRef.cs | 7 ++++++-
src/Lucene.Net/Util/PagedBytes.cs | 7 ++++++-
src/Lucene.Net/Util/WAH8DocIdSet.cs | 7 +++++--
9 files changed, 53 insertions(+), 11 deletions(-)
diff --git a/src/Lucene.Net/Util/Bits.cs b/src/Lucene.Net/Util/Bits.cs
index d1cbcf9..c267de9 100644
--- a/src/Lucene.Net/Util/Bits.cs
+++ b/src/Lucene.Net/Util/Bits.cs
@@ -1,3 +1,5 @@
+using System;
+
namespace Lucene.Net.Util
{
/*
@@ -40,8 +42,12 @@ namespace Lucene.Net.Util
public static class Bits
{
- public static readonly IBits[] EMPTY_ARRAY = new IBits[0];
-
+ public static readonly IBits[] EMPTY_ARRAY =
+#if FEATURE_ARRAYEMPTY
+ Array.Empty<IBits>();
+#else
+ new IBits[0];
+#endif
/// <summary>
/// Bits impl of the specified length with all bits set.
/// </summary>
diff --git a/src/Lucene.Net/Util/BytesRef.cs b/src/Lucene.Net/Util/BytesRef.cs
index 7697ecd..7398e5e 100644
--- a/src/Lucene.Net/Util/BytesRef.cs
+++ b/src/Lucene.Net/Util/BytesRef.cs
@@ -47,7 +47,12 @@ namespace Lucene.Net.Util
{
/// <summary>
/// An empty byte array for convenience </summary>
- public static readonly byte[] EMPTY_BYTES = new byte[0];
+ public static readonly byte[] EMPTY_BYTES =
+#if FEATURE_ARRAYEMPTY
+ Array.Empty<byte>();
+#else
+ new byte[0];
+#endif
/// <summary>
/// The contents of the BytesRef. Should never be <c>null</c>.
diff --git a/src/Lucene.Net/Util/CharsRef.cs b/src/Lucene.Net/Util/CharsRef.cs
index c84296c..9290237 100644
--- a/src/Lucene.Net/Util/CharsRef.cs
+++ b/src/Lucene.Net/Util/CharsRef.cs
@@ -41,8 +41,12 @@ namespace Lucene.Net.Util
{
/// <summary>
/// An empty character array for convenience </summary>
- public static readonly char[] EMPTY_CHARS = new char[0];
-
+ public static readonly char[] EMPTY_CHARS =
+#if FEATURE_ARRAYEMPTY
+ Array.Empty<char>();
+#else
+ new char[0];
+#endif
bool ICharSequence.HasValue => true;
/// <summary>
diff --git a/src/Lucene.Net/Util/FieldCacheSanityChecker.cs b/src/Lucene.Net/Util/FieldCacheSanityChecker.cs
index ff58d0f..923b16e 100644
--- a/src/Lucene.Net/Util/FieldCacheSanityChecker.cs
+++ b/src/Lucene.Net/Util/FieldCacheSanityChecker.cs
@@ -105,7 +105,11 @@ namespace Lucene.Net.Util
{
if (null == cacheEntries || 0 == cacheEntries.Length)
{
+#if FEATURE_ARRAYEMPTY
+ return Array.Empty<Insanity>();
+#else
return new Insanity[0];
+#endif
}
if (estimateRam)
diff --git a/src/Lucene.Net/Util/Fst/FST.cs b/src/Lucene.Net/Util/Fst/FST.cs
index ffb4661..b3c2a41 100644
--- a/src/Lucene.Net/Util/Fst/FST.cs
+++ b/src/Lucene.Net/Util/Fst/FST.cs
@@ -105,7 +105,12 @@ namespace Lucene.Net.Util.Fst
/// <seealso cref= #shouldExpand(UnCompiledNode) </seealso>
internal const int FIXED_ARRAY_NUM_ARCS_DEEP = 10;*/
- private int[] bytesPerArc = new int[0];
+ private int[] bytesPerArc =
+#if FEATURE_ARRAYEMPTY
+ Array.Empty<int>();
+#else
+ new int[0];
+#endif
/*// Increment version to change it
private const string FILE_FORMAT_NAME = "FST";
diff --git a/src/Lucene.Net/Util/IntsRef.cs b/src/Lucene.Net/Util/IntsRef.cs
index 7d0b228..545dfac 100644
--- a/src/Lucene.Net/Util/IntsRef.cs
+++ b/src/Lucene.Net/Util/IntsRef.cs
@@ -45,7 +45,12 @@ namespace Lucene.Net.Util
/// <para/>
/// NOTE: This was EMPTY_INTS in Lucene
/// </summary>
- public static readonly int[] EMPTY_INT32S = new int[0];
+ public static readonly int[] EMPTY_INT32S =
+#if FEATURE_ARRAYEMPTY
+ Array.Empty<int>();
+#else
+ new int[0];
+#endif
/// <summary>
/// The contents of the <see cref="Int32sRef"/>. Should never be <c>null</c>.
diff --git a/src/Lucene.Net/Util/LongsRef.cs b/src/Lucene.Net/Util/LongsRef.cs
index 7a1f976..9717c28 100644
--- a/src/Lucene.Net/Util/LongsRef.cs
+++ b/src/Lucene.Net/Util/LongsRef.cs
@@ -45,7 +45,12 @@ namespace Lucene.Net.Util
/// <para/>
/// NOTE: This was EMPTY_LONGS in Lucene
/// </summary>
- public static readonly long[] EMPTY_INT64S = new long[0];
+ public static readonly long[] EMPTY_INT64S =
+#if FEATURE_ARRAYEMPTY
+ Array.Empty<long>();
+#else
+ new long[0];
+#endif
/// <summary>
/// The contents of the <see cref="Int64sRef"/>. Should never be <c>null</c>.
diff --git a/src/Lucene.Net/Util/PagedBytes.cs b/src/Lucene.Net/Util/PagedBytes.cs
index ad5fea3..145d1e8 100644
--- a/src/Lucene.Net/Util/PagedBytes.cs
+++ b/src/Lucene.Net/Util/PagedBytes.cs
@@ -51,7 +51,12 @@ namespace Lucene.Net.Util
private byte[] currentBlock;
private readonly long bytesUsedPerBlock;
- private static readonly byte[] EMPTY_BYTES = new byte[0];
+ private static readonly byte[] EMPTY_BYTES =
+#if FEATURE_ARRAYEMPTY
+ Array.Empty<byte>();
+#else
+ new byte[0];
+#endif
/// <summary>
/// Provides methods to read <see cref="BytesRef"/>s from a frozen
diff --git a/src/Lucene.Net/Util/WAH8DocIdSet.cs b/src/Lucene.Net/Util/WAH8DocIdSet.cs
index b5f21fa..6679504 100644
--- a/src/Lucene.Net/Util/WAH8DocIdSet.cs
+++ b/src/Lucene.Net/Util/WAH8DocIdSet.cs
@@ -88,8 +88,11 @@ namespace Lucene.Net.Util
public const int DEFAULT_INDEX_INTERVAL = 24;
private static readonly MonotonicAppendingInt64Buffer SINGLE_ZERO_BUFFER = LoadSingleZeroBuffer();
- private static WAH8DocIdSet EMPTY = new WAH8DocIdSet(new byte[0], 0, 1, SINGLE_ZERO_BUFFER, SINGLE_ZERO_BUFFER);
-
+#if FEATURE_ARRAYEMPTY
+ private static WAH8DocIdSet EMPTY = new WAH8DocIdSet(Array.Empty<byte>(), 0, 1, SINGLE_ZERO_BUFFER, SINGLE_ZERO_BUFFER);
+#else
+ private static WAH8DocIdSet EMPTY = new WAH8DocIdSet(new byte[0], 0, 1, SINGLE_ZERO_BUFFER, SINGLE_ZERO_BUFFER);
+#endif
private static MonotonicAppendingInt64Buffer LoadSingleZeroBuffer() // LUCENENET: Avoid static constructors (see https://github.com/apache/lucenenet/pull/224#issuecomment-469284006)
{
var buffer = new MonotonicAppendingInt64Buffer(1, 64, PackedInt32s.COMPACT);