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 2022/11/12 11:13:20 UTC

[lucenenet] branch master updated (cf259c918 -> dc2955699)

This is an automated email from the ASF dual-hosted git repository.

nightowl888 pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git


    from cf259c918 fix: Aligned disposable patterns (#746)
     new eb85c679d Lucene.Net.Analysis.Util.BufferedCharFilter: Use UninterruptableMonitor for consistency (missed a couple)
     new ceafc83ad Lucene.Net.Analysis.Util.BufferedCharFilter: Check for CharFilter type inline
     new dc2955699 Lucene.Net.Analysis.Util.BufferedCharFilter: Implemented Peek() method. Added overrides for Span<T> and Memory<T> based methods to throw NotSupportedException. Added doc comments.

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 Directory.Build.targets                            |   6 +-
 .../Analysis/Util/BufferedCharFilter.cs            | 145 ++++++++++++++++++---
 src/Lucene.Net/Support/IO/SafeTextWriterWrapper.cs |   2 +
 3 files changed, 135 insertions(+), 18 deletions(-)


[lucenenet] 03/03: Lucene.Net.Analysis.Util.BufferedCharFilter: Implemented Peek() method. Added overrides for Span and Memory based methods to throw NotSupportedException. Added doc comments.

Posted by ni...@apache.org.
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 dc2955699e2b8a2bf31813a819d17749eb7d4a4b
Author: Shad Storhaug <sh...@shadstorhaug.com>
AuthorDate: Sat Nov 12 17:44:19 2022 +0700

    Lucene.Net.Analysis.Util.BufferedCharFilter: Implemented Peek() method. Added overrides for Span<T> and Memory<T> based methods to throw NotSupportedException. Added doc comments.
---
 Directory.Build.targets                            |   6 +-
 .../Analysis/Util/BufferedCharFilter.cs            | 125 +++++++++++++++++++--
 src/Lucene.Net/Support/IO/SafeTextWriterWrapper.cs |   2 +
 3 files changed, 121 insertions(+), 12 deletions(-)

diff --git a/Directory.Build.targets b/Directory.Build.targets
index fc876a7b4..3065ed7af 100644
--- a/Directory.Build.targets
+++ b/Directory.Build.targets
@@ -80,9 +80,11 @@
 
   </PropertyGroup>
 
-  <!-- Features in .NET Framework 4.5+, .NET Standard 2.x, .NET Core 2.x, .NET Core 3.x, .NET 5.x (No .NET 6.x support) -->
-  <PropertyGroup Condition=" $(TargetFramework.StartsWith('net4')) Or $(TargetFramework.StartsWith('netstandard2.')) Or $(TargetFramework.StartsWith('netcoreapp2.')) Or $(TargetFramework.StartsWith('netcoreapp3.')) Or '$(TargetFramework)' == 'net5.0' ">
+  <!-- Features in .NET Framework 4.5+ and .NET Standard 2.x only (No .NET Core support) -->
+  <PropertyGroup Condition=" $(TargetFramework.StartsWith('net4')) Or $(TargetFramework.StartsWith('netstandard2.')) ">
 
+    <!-- NOTE: The API for this exists in .NET Core, but it throws a PlatformNotSupportedException.
+         We simply don't override this to get the same behavior. -->
     <DefineConstants>$(DefineConstants);FEATURE_TEXTWRITER_INITIALIZELIFETIMESERVICE</DefineConstants>
 
   </PropertyGroup>
diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Util/BufferedCharFilter.cs b/src/Lucene.Net.Analysis.Common/Analysis/Util/BufferedCharFilter.cs
index e073fc95d..0a683a9a2 100644
--- a/src/Lucene.Net.Analysis.Common/Analysis/Util/BufferedCharFilter.cs
+++ b/src/Lucene.Net.Analysis.Common/Analysis/Util/BufferedCharFilter.cs
@@ -7,6 +7,7 @@ using Lucene.Net.Support.Threading;
 using System;
 using System.IO;
 using System.Text;
+using System.Threading;
 using System.Threading.Tasks;
 
 namespace Lucene.Net.Analysis.Util
@@ -608,50 +609,154 @@ namespace Lucene.Net.Analysis.Util
             }
         }
 
-#region LUCENENET Specific Methods
+        #region LUCENENET Specific Methods
 
+        /// <summary>
+        /// Reads a single character from this reader and returns it with the two
+        /// higher-order bytes set to 0. If possible, <see cref="BufferedCharFilter"/> returns a
+        /// character from the buffer. If there are no characters available in the
+        /// buffer, it fills the buffer and then returns a character. It returns -1
+        /// if there are no more characters in the source reader. Unlike <see cref="Read()"/>,
+        /// this method does not advance the current position.
+        /// </summary>
+        /// <returns>The character read or -1 if the end of the source reader has been reached.</returns>
+        /// <exception cref="IOException">If this reader is disposed or some other I/O error occurs.</exception>
         public override int Peek()
         {
-            throw new NotImplementedException();
+            UninterruptableMonitor.Enter(m_lock);
+            try
+            {
+                EnsureOpen();
+                /* Are there buffered characters available? */
+                if (pos < end || FillBuf() != -1)
+                {
+                    return buf[pos];
+                }
+                return -1;
+            }
+            finally
+            {
+                UninterruptableMonitor.Exit(m_lock);
+            }
         }
 
+        /// <inheritdoc/>
+        public override bool Equals(object obj) => @in.Equals(obj);
+
+        /// <inheritdoc/>
+        public override int GetHashCode() => @in.GetHashCode();
+
+        /// <inheritdoc/>
+        public override string ToString() => @in.ToString();
+
+#if FEATURE_STREAM_READ_SPAN
+        /// <summary>
+        /// Not supported.
+        /// </summary>
+        /// <exception cref="NotSupportedException">In all cases.</exception>
+        public override int Read(Span<char> buffer)
+        {
+            throw UnsupportedOperationException.Create();
+        }
+
+        /// <summary>
+        /// Not supported.
+        /// </summary>
+        /// <exception cref="NotSupportedException">In all cases.</exception>
+        public override ValueTask<int> ReadAsync(Memory<char> buffer, CancellationToken cancellationToken = default)
+        {
+            throw UnsupportedOperationException.Create();
+        }
+
+        /// <summary>
+        /// Not supported.
+        /// </summary>
+        /// <exception cref="NotSupportedException">In all cases.</exception>
+        public override int ReadBlock(Span<char> buffer)
+        {
+            throw UnsupportedOperationException.Create();
+        }
+
+        /// <summary>
+        /// Not supported.
+        /// </summary>
+        /// <exception cref="NotSupportedException">In all cases.</exception>
+        public override ValueTask<int> ReadBlockAsync(Memory<char> buffer, CancellationToken cancellationToken = default)
+        {
+            throw UnsupportedOperationException.Create();
+        }
+#endif
+        /// <summary>
+        /// Not supported.
+        /// </summary>
+        /// <exception cref="NotSupportedException">In all cases.</exception>
         public override Task<int> ReadAsync(char[] buffer, int index, int count)
         {
-            throw new NotImplementedException();
+            throw UnsupportedOperationException.Create();
         }
 
+        /// <summary>
+        /// Not supported.
+        /// </summary>
+        /// <exception cref="NotSupportedException">In all cases.</exception>
         public override int ReadBlock(char[] buffer, int index, int count)
         {
-            throw new NotImplementedException();
+            throw UnsupportedOperationException.Create();
         }
 
+        /// <summary>
+        /// Not supported.
+        /// </summary>
+        /// <exception cref="NotSupportedException">In all cases.</exception>
         public override Task<int> ReadBlockAsync(char[] buffer, int index, int count)
         {
-            throw new NotImplementedException();
+            throw UnsupportedOperationException.Create();
         }
 
+        /// <summary>
+        /// Not supported.
+        /// </summary>
+        /// <exception cref="NotSupportedException">In all cases.</exception>
         public override Task<string> ReadLineAsync()
         {
-            throw new NotImplementedException();
+            throw UnsupportedOperationException.Create();
         }
 
+        /// <summary>
+        /// Not supported.
+        /// </summary>
+        /// <exception cref="NotSupportedException">In all cases.</exception>
         public override string ReadToEnd()
         {
-            throw new NotImplementedException();
+            throw UnsupportedOperationException.Create();
         }
 
+        /// <summary>
+        /// Not supported.
+        /// </summary>
+        /// <exception cref="NotSupportedException">In all cases.</exception>
         public override Task<string> ReadToEndAsync()
         {
-            throw new NotImplementedException();
+            throw UnsupportedOperationException.Create();
         }
 #if FEATURE_TEXTWRITER_INITIALIZELIFETIMESERVICE
+        /// <summary>
+        /// Not supported.
+        /// </summary>
+        /// <exception cref="NotSupportedException">In all cases.</exception>
+        // LUCENENET: We don't override this on .NET Core, it throws a
+        // PlatformNotSupportedException, which is the behavior we want.
         public override object InitializeLifetimeService()
         {
-            throw new NotImplementedException();
+            throw UnsupportedOperationException.Create();
         }
 #endif
 
 #if FEATURE_TEXTWRITER_CLOSE
+        /// <summary>
+        /// Not supported.
+        /// </summary>
+        /// <exception cref="NotSupportedException">The call didn't originate from within <see cref="Dispose(bool)"/>.</exception>
         public override void Close()
         {
             if (!isDisposing)
@@ -660,6 +765,6 @@ namespace Lucene.Net.Analysis.Util
             }
         }
 #endif
-        #endregion
+        #endregion LUCENENET Specific Methods
     }
 }
\ No newline at end of file
diff --git a/src/Lucene.Net/Support/IO/SafeTextWriterWrapper.cs b/src/Lucene.Net/Support/IO/SafeTextWriterWrapper.cs
index 29fae0a5d..89dae6741 100644
--- a/src/Lucene.Net/Support/IO/SafeTextWriterWrapper.cs
+++ b/src/Lucene.Net/Support/IO/SafeTextWriterWrapper.cs
@@ -93,6 +93,8 @@ namespace Lucene.Net.Support.IO
         }
 
 #if FEATURE_TEXTWRITER_INITIALIZELIFETIMESERVICE
+        // LUCENENET: We don't override this on .NET Core, it throws a
+        // PlatformNotSupportedException, which is the behavior we want.
         public override object InitializeLifetimeService()
         {
             return Run(() => textWriter.InitializeLifetimeService());


[lucenenet] 01/03: Lucene.Net.Analysis.Util.BufferedCharFilter: Use UninterruptableMonitor for consistency (missed a couple)

Posted by ni...@apache.org.
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 eb85c679d35323e3ed1f1a720e652ab30415cbd7
Author: Shad Storhaug <sh...@shadstorhaug.com>
AuthorDate: Sat Nov 12 16:08:42 2022 +0700

    Lucene.Net.Analysis.Util.BufferedCharFilter: Use UninterruptableMonitor for consistency (missed a couple)
---
 .../Analysis/Util/BufferedCharFilter.cs                    | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Util/BufferedCharFilter.cs b/src/Lucene.Net.Analysis.Common/Analysis/Util/BufferedCharFilter.cs
index 8bf2ee334..71ecfb9ca 100644
--- a/src/Lucene.Net.Analysis.Common/Analysis/Util/BufferedCharFilter.cs
+++ b/src/Lucene.Net.Analysis.Common/Analysis/Util/BufferedCharFilter.cs
@@ -303,7 +303,8 @@ namespace Lucene.Net.Analysis.Util
         /// <exception cref="IOException">if this reader is disposed or some other I/O error occurs.</exception>
         public override int Read(char[] buffer, int offset, int length)
         {
-            lock(m_lock)
+            UninterruptableMonitor.Enter(m_lock);
+            try
             {
                 EnsureOpen();
                 // LUCENENT specific - refactored guard clauses to throw individual messages.
@@ -379,6 +380,10 @@ namespace Lucene.Net.Analysis.Util
                 int count = length - outstanding;
                 return (count > 0 || count == length) ? count : 0 /*-1*/;
             }
+            finally
+            {
+                UninterruptableMonitor.Exit(m_lock);
+            }
         }
 
         /// <summary>
@@ -392,7 +397,8 @@ namespace Lucene.Net.Analysis.Util
         /// <exception cref="IOException">if this reader is disposed or some other I/O error occurs.</exception>
         public override string ReadLine()
         {
-            lock(m_lock)
+            UninterruptableMonitor.Enter(m_lock);
+            try
             {
                 EnsureOpen();
                 /* has the underlying stream been exhausted? */
@@ -487,6 +493,10 @@ namespace Lucene.Net.Analysis.Util
                     }
                 }
             }
+            finally
+            {
+                UninterruptableMonitor.Exit(m_lock);
+            }
         }
 
         /// <summary>


[lucenenet] 02/03: Lucene.Net.Analysis.Util.BufferedCharFilter: Check for CharFilter type inline

Posted by ni...@apache.org.
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 ceafc83ad4585ceddf767158aeae44b246c65531
Author: Shad Storhaug <sh...@shadstorhaug.com>
AuthorDate: Sat Nov 12 16:24:16 2022 +0700

    Lucene.Net.Analysis.Util.BufferedCharFilter: Check for CharFilter type inline
---
 src/Lucene.Net.Analysis.Common/Analysis/Util/BufferedCharFilter.cs | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Util/BufferedCharFilter.cs b/src/Lucene.Net.Analysis.Common/Analysis/Util/BufferedCharFilter.cs
index 71ecfb9ca..e073fc95d 100644
--- a/src/Lucene.Net.Analysis.Common/Analysis/Util/BufferedCharFilter.cs
+++ b/src/Lucene.Net.Analysis.Common/Analysis/Util/BufferedCharFilter.cs
@@ -343,8 +343,7 @@ namespace Lucene.Net.Analysis.Util
                      * underlying stream would block.
                      */
                     // LUCENENET specific: only CharFilter derived types support IsReady
-                    var charFilter = @in as CharFilter;
-                    if (outstanding == 0 || (outstanding < length) && charFilter != null && !charFilter.IsReady)
+                    if (outstanding == 0 || (outstanding < length) && @in is CharFilter charFilter && !charFilter.IsReady)
                     {
                         break;
                     }
@@ -515,8 +514,7 @@ namespace Lucene.Net.Analysis.Util
                 {
                     EnsureOpen();
                     // LUCENENET specific: only CharFilter derived types support IsReady
-                    var charFilter = @in as CharFilter;
-                    return ((end - pos) > 0) || (charFilter != null && charFilter.IsReady);
+                    return ((end - pos) > 0) || (@in is CharFilter charFilter && charFilter.IsReady);
                 }
                 finally
                 {