NightOwl888 commented on code in PR #1144:
URL: https://github.com/apache/lucenenet/pull/1144#discussion_r2395470320
##########
src/Lucene.Net.Analysis.Common/Analysis/Util/StemmerUtil.cs:
##########
@@ -111,14 +195,35 @@ public static bool EndsWith(char[] s, int len, char[]
suffix)
/// <param name="pos"> Position of character to delete </param>
/// <param name="len"> length of input buffer </param>
/// <returns> length of input buffer after deletion </returns>
- public static int Delete(char[] s, int pos, int len)
+ /// <remarks>
+ /// LUCENENET NOTE: This method has been converted to use <see
cref="Span{T}"/>.
+ /// Callers should prefer the overload without the <paramref
name="len"/> parameter and use a slice instead,
+ /// but this overload is provided for compatibility with existing code.
+ /// </remarks>
+ internal static int Delete(Span<char> s, int pos, int len)
{
- if (Debugging.AssertsEnabled) Debugging.Assert(pos < len);
- if (pos < len - 1) // don't arraycopy if asked to delete last
character
+ return Delete(s.Slice(0, len), pos);
+ }
+
+ /// <summary>
+ /// Delete n characters in-place
+ /// </summary>
+ /// <param name="s"> Input Buffer </param>
+ /// <param name="pos"> Position of character to delete </param>
+ /// <param name="nChars"> number of characters to delete </param>
+ /// <returns> length of input buffer after deletion </returns>
+ /// <remarks>
+ /// LUCENENET NOTE: This method has been converted to use <see
cref="Span{T}"/>.
+ /// </remarks>
+ public static int DeleteN(Span<char> s, int pos, int nChars)
+ {
+ if (Debugging.AssertsEnabled) Debugging.Assert(pos + nChars <=
s.Length);
+ if (pos + nChars < s.Length) // don't arraycopy if asked to delete
the last characters
{
- Arrays.Copy(s, pos + 1, s, pos, len - pos - 1);
+ // Arrays.Copy(s, pos + nChars, s, pos, len - pos - nChars);
+ s.Slice(pos + nChars, s.Length - pos -
nChars).CopyTo(s.Slice(pos, s.Length - pos - nChars));
Review Comment:
The syntax would be simpler with the `Arrays.Copy()` overloads that accept
spans, which are now in master. They are set up to be aggressively inlined so
if the compiler respects that, there should be no difference in performance.
##########
src/Lucene.Net.Analysis.Common/Analysis/Util/StemmerUtil.cs:
##########
@@ -86,22 +156,36 @@ public static bool EndsWith(char[] s, int len, string
suffix)
/// <param name="len"> length of input buffer </param>
/// <param name="suffix"> Suffix string to test </param>
/// <returns> <c>true</c> if <paramref name="s"/> ends with <paramref
name="suffix"/> </returns>
- public static bool EndsWith(char[] s, int len, char[] suffix)
+ /// <remarks>
+ /// LUCENENET NOTE: This method has been converted to use <see
cref="ReadOnlySpan{T}"/>.
+ /// Callers should prefer the overload without the <paramref
name="len"/> parameter and use a slice instead,
+ /// but this overload is provided for compatibility with existing code.
+ /// </remarks>
+ internal static bool EndsWith(ReadOnlySpan<char> s, int len,
ReadOnlySpan<char> suffix)
{
- int suffixLen = suffix.Length;
- if (suffixLen > len)
- {
- return false;
- }
- for (int i = suffixLen - 1; i >= 0; i--)
+ return EndsWith(s.Slice(0, len), suffix);
+ }
+
+ // LUCENENET NOTE: char[] overload of EndsWith removed because the
ReadOnlySpan<char> overload can be used instead
+
+ /// <summary>
+ /// Delete a character in-place
+ /// </summary>
+ /// <param name="s"> Input Buffer </param>
+ /// <param name="pos"> Position of character to delete </param>
+ /// <returns> length of input buffer after deletion </returns>
+ /// <remarks>
+ /// LUCENENET NOTE: This method has been converted to use <see
cref="Span{T}"/>.
+ /// </remarks>
+ public static int Delete(Span<char> s, int pos)
+ {
+ if (Debugging.AssertsEnabled) Debugging.Assert(pos < s.Length);
+ if (pos < s.Length - 1) // don't arraycopy if asked to delete last
character
{
- if (s[len - (suffixLen - i)] != suffix[i])
- {
- return false;
- }
+ // Arrays.Copy(s, pos + 1, s, pos, len - pos - 1);
+ s.Slice(pos + 1, s.Length - pos - 1).CopyTo(s.Slice(pos,
s.Length - pos - 1));
Review Comment:
The syntax would be simpler with the `Arrays.Copy()` overloads that accept
spans, which are now in master. They are set up to be aggressively inlined so
if the compiler respects that, there should be no difference in performance.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]