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 f5cca0b1a7c855f2fe44a5cdd27763aab7acdf22
Author: Shad Storhaug <[email protected]>
AuthorDate: Sun Oct 4 06:18:43 2020 +0700

    Lucene.Net.Util.Counter: Changed Get() to Value property and added implicit 
operator.
---
 src/Lucene.Net/Index/DocumentsWriterPerThread.cs   |  2 +-
 src/Lucene.Net/Search/TimeLimitingCollector.cs     |  6 +++---
 src/Lucene.Net/Util/Counter.cs                     | 22 ++++++++++++++++------
 src/Lucene.Net/Util/OfflineSorter.cs               |  2 +-
 src/Lucene.Net/Util/RecyclingByteBlockAllocator.cs |  6 +++---
 src/Lucene.Net/Util/RecyclingIntBlockAllocator.cs  |  6 +++---
 6 files changed, 27 insertions(+), 17 deletions(-)

diff --git a/src/Lucene.Net/Index/DocumentsWriterPerThread.cs 
b/src/Lucene.Net/Index/DocumentsWriterPerThread.cs
index 3a5ca37..e754738 100644
--- a/src/Lucene.Net/Index/DocumentsWriterPerThread.cs
+++ b/src/Lucene.Net/Index/DocumentsWriterPerThread.cs
@@ -681,7 +681,7 @@ namespace Lucene.Net.Index
         /// Get current segment info we are writing. </summary>
         internal virtual SegmentInfo SegmentInfo => segmentInfo;
 
-        public virtual long BytesUsed => bytesUsed.Get() + 
pendingUpdates.bytesUsed;
+        public virtual long BytesUsed => bytesUsed + pendingUpdates.bytesUsed;
 
         /// <summary>
         /// Initial chunks size of the shared byte[] blocks used to
diff --git a/src/Lucene.Net/Search/TimeLimitingCollector.cs 
b/src/Lucene.Net/Search/TimeLimitingCollector.cs
index e4f9d41..121cc89 100644
--- a/src/Lucene.Net/Search/TimeLimitingCollector.cs
+++ b/src/Lucene.Net/Search/TimeLimitingCollector.cs
@@ -147,12 +147,12 @@ namespace Lucene.Net.Search
         }
 
         /// <summary>
-        /// Syntactic sugar for <see cref="SetBaseline(long)"/> using <see 
cref="Counter.Get()"/>
+        /// Syntactic sugar for <see cref="SetBaseline(long)"/> using <see 
cref="Counter.Value"/>
         /// on the clock passed to the constructor.
         /// </summary>
         public virtual void SetBaseline()
         {
-            SetBaseline(clock.Get());
+            SetBaseline(clock);
         }
 
         /// <summary>
@@ -176,7 +176,7 @@ namespace Lucene.Net.Search
         ///           If the time allowed has exceeded. </exception>
         public virtual void Collect(int doc)
         {
-            long time = clock.Get();
+            long time = clock;
             if (timeout < time)
             {
                 if (greedy)
diff --git a/src/Lucene.Net/Util/Counter.cs b/src/Lucene.Net/Util/Counter.cs
index f8afcf7..8c72ac6 100644
--- a/src/Lucene.Net/Util/Counter.cs
+++ b/src/Lucene.Net/Util/Counter.cs
@@ -1,4 +1,5 @@
 using J2N.Threading.Atomic;
+using System;
 
 namespace Lucene.Net.Util
 {
@@ -36,10 +37,16 @@ namespace Lucene.Net.Util
         public abstract long AddAndGet(long delta);
 
         /// <summary>
+        /// Gets the counters current value.
+        /// </summary>
+        public abstract long Value { get; }
+
+        /// <summary>
         /// Returns the counters current value.
         /// </summary>
         /// <returns> The counters current value. </returns>
-        public abstract long Get(); // LUCENENET TODO: API: Change to Value 
property and add implicit operator to get
+        [Obsolete("Use Value instead. This method will be removed in 4.8.0 
release candidate.")]
+        public virtual long Get() => Value;
 
         /// <summary>
         /// Returns a new counter. The returned counter is not thread-safe.
@@ -61,6 +68,12 @@ namespace Lucene.Net.Util
             return threadSafe ? (Counter)new AtomicCounter() : new 
SerialCounter();
         }
 
+        /// <summary>
+        /// Returns this counter's <see cref="Value"/> implicitly.
+        /// </summary>
+        /// <param name="counter"></param>
+        public static implicit operator long(Counter counter) => 
counter.Value; // LUCENENET specific
+
         private sealed class SerialCounter : Counter
         {
             private long count = 0;
@@ -70,10 +83,7 @@ namespace Lucene.Net.Util
                 return count += delta;
             }
 
-            public override long Get()
-            {
-                return count;
-            }
+            public override long Value => count;
         }
 
         private sealed class AtomicCounter : Counter
@@ -85,7 +95,7 @@ namespace Lucene.Net.Util
                 return count.AddAndGet(delta);
             }
 
-            public override long Get() => count;
+            public override long Value => count;
         }
     }
 }
\ No newline at end of file
diff --git a/src/Lucene.Net/Util/OfflineSorter.cs 
b/src/Lucene.Net/Util/OfflineSorter.cs
index 0526210..8084522 100644
--- a/src/Lucene.Net/Util/OfflineSorter.cs
+++ b/src/Lucene.Net/Util/OfflineSorter.cs
@@ -465,7 +465,7 @@ namespace Lucene.Net.Util
                 buffer.Append(scratch);
                 // Account for the created objects.
                 // (buffer slots do not account to buffer size.)
-                if (ramBufferSize.bytes < bufferBytesUsed.Get())
+                if (ramBufferSize.bytes < bufferBytesUsed)
                 {
                     break;
                 }
diff --git a/src/Lucene.Net/Util/RecyclingByteBlockAllocator.cs 
b/src/Lucene.Net/Util/RecyclingByteBlockAllocator.cs
index 737ca9b..df90ff1 100644
--- a/src/Lucene.Net/Util/RecyclingByteBlockAllocator.cs
+++ b/src/Lucene.Net/Util/RecyclingByteBlockAllocator.cs
@@ -109,14 +109,14 @@ namespace Lucene.Net.Util
                 blocks[i] = null;
             }
             bytesUsed.AddAndGet(-(end - stop) * m_blockSize);
-            if (Debugging.AssertsEnabled) Debugging.Assert(bytesUsed.Get() >= 
0);
+            if (Debugging.AssertsEnabled) Debugging.Assert(bytesUsed >= 0);
         }
 
         /// <returns> The number of currently buffered blocks. </returns>
         public int NumBufferedBlocks => freeBlocks;
 
         /// <returns> The number of bytes currently allocated by this <see 
cref="ByteBlockPool.Allocator"/>. </returns>
-        public long BytesUsed => bytesUsed.Get();
+        public long BytesUsed => bytesUsed;
 
         /// <returns> The maximum number of buffered byte blocks. </returns>
         public int MaxBufferedBlocks => maxBufferedBlocks;
@@ -147,7 +147,7 @@ namespace Lucene.Net.Util
                 freeByteBlocks[--freeBlocks] = null;
             }
             bytesUsed.AddAndGet(-count * m_blockSize);
-            if (Debugging.AssertsEnabled) Debugging.Assert(bytesUsed.Get() >= 
0);
+            if (Debugging.AssertsEnabled) Debugging.Assert(bytesUsed >= 0);
             return count;
         }
     }
diff --git a/src/Lucene.Net/Util/RecyclingIntBlockAllocator.cs 
b/src/Lucene.Net/Util/RecyclingIntBlockAllocator.cs
index a8d518e..b741658 100644
--- a/src/Lucene.Net/Util/RecyclingIntBlockAllocator.cs
+++ b/src/Lucene.Net/Util/RecyclingIntBlockAllocator.cs
@@ -120,14 +120,14 @@ namespace Lucene.Net.Util
                 blocks[i] = null;
             }
             bytesUsed.AddAndGet(-(end - stop) * (m_blockSize * 
RamUsageEstimator.NUM_BYTES_INT32));
-            if (Debugging.AssertsEnabled) Debugging.Assert(bytesUsed.Get() >= 
0);
+            if (Debugging.AssertsEnabled) Debugging.Assert(bytesUsed >= 0);
         }
 
         /// <returns> The number of currently buffered blocks. </returns>
         public int NumBufferedBlocks => freeBlocks;
 
         /// <returns> The number of bytes currently allocated by this <see 
cref="Allocator"/>. </returns>
-        public long BytesUsed => bytesUsed.Get();
+        public long BytesUsed => bytesUsed;
 
         /// <returns> The maximum number of buffered byte blocks. </returns>
         public int MaxBufferedBlocks => maxBufferedBlocks;
@@ -158,7 +158,7 @@ namespace Lucene.Net.Util
                 freeByteBlocks[--freeBlocks] = null;
             }
             bytesUsed.AddAndGet(-count * m_blockSize * 
RamUsageEstimator.NUM_BYTES_INT32);
-            if (Debugging.AssertsEnabled) Debugging.Assert(bytesUsed.Get() >= 
0);
+            if (Debugging.AssertsEnabled) Debugging.Assert(bytesUsed >= 0);
             return count;
         }
     }

Reply via email to