();
ruleMapping[patternKey] = rules;
@@ -437,34 +440,7 @@ private string Cleanup(string input)
return sb.ToString();
}
- // LUCENENET specific - in .NET we don't need an object overload, since strings are sealed anyway.
- //**
- // * Encodes an Object using the Daitch-Mokotoff soundex algorithm without branching.
- // *
- // * This method is provided in order to satisfy the requirements of the Encoder interface, and will throw an
- // * EncoderException if the supplied object is not of type java.lang.String.
- // *
- // *
- // * @see #soundex(String)
- // *
- // * @param obj
- // * Object to encode
- // * @return An object (of type java.lang.String) containing the DM soundex code, which corresponds to the String
- // * supplied.
- // * @throws EncoderException
- // * if the parameter supplied is not of type java.lang.String
- // * @throws IllegalArgumentException
- // * if a character is not mapped
- // */
- //@Override
- // public Object encode(object obj)
- //{
- // if (!(obj instanceof String)) {
- // throw new EncoderException(
- // "Parameter supplied to DaitchMokotoffSoundex encode is not of type java.lang.String");
- // }
- // return encode((String) obj);
- //}
+ // LUCENENET specific - in .NET we don't need an object overload of Encode(), since strings are sealed anyway.
///
/// Encodes a string using the Daitch-Mokotoff soundex algorithm without branching.
@@ -473,6 +449,7 @@ private string Cleanup(string input)
/// A DM Soundex code corresponding to the string supplied.
/// If a character is not mapped.
///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public virtual string Encode(string source)
{
if (source == null)
@@ -532,8 +509,10 @@ private string[] GetSoundex(string source, bool branching)
string input = Cleanup(source);
// LinkedHashSet preserves input order. In .NET we can use List for that purpose.
- IList currentBranches = new List();
- currentBranches.Add(new Branch());
+ IList currentBranches = new List
+ {
+ new Branch()
+ };
char lastChar = '\0';
for (int index = 0; index < input.Length; index++)
@@ -547,8 +526,7 @@ private string[] GetSoundex(string source, bool branching)
}
string inputContext = input.Substring(index);
- IList rules;
- if (!RULES.TryGetValue(ch, out rules) || rules == null)
+ if (!RULES.TryGetValue(ch, out IList rules) || rules == null)
{
continue;
}
diff --git a/src/Lucene.Net.Analysis.Phonetic/Language/DoubleMetaphone.cs b/src/Lucene.Net.Analysis.Phonetic/Language/DoubleMetaphone.cs
index 73eb64f549..17bd705f74 100644
--- a/src/Lucene.Net.Analysis.Phonetic/Language/DoubleMetaphone.cs
+++ b/src/Lucene.Net.Analysis.Phonetic/Language/DoubleMetaphone.cs
@@ -1,6 +1,7 @@
// commons-codec version compatibility level: 1.9
using System;
using System.Globalization;
+using System.Runtime.CompilerServices;
using System.Text;
namespace Lucene.Net.Analysis.Phonetic.Language
@@ -40,7 +41,7 @@ public class DoubleMetaphone : IStringEncoder
///
/// "Vowels" to test for
///
- private static readonly string VOWELS = "AEIOUY";
+ private const string VOWELS = "AEIOUY";
///
/// Prefixes when present which are not pronounced
@@ -72,6 +73,7 @@ public DoubleMetaphone()
///
/// String to encode.
/// An encoded string.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public virtual string GetDoubleMetaphone(string value)
{
return GetDoubleMetaphone(value, false);
@@ -194,29 +196,14 @@ public virtual string GetDoubleMetaphone(string value, bool alternate)
return alternate ? result.Alternate : result.Primary;
}
- // LUCENENET specific - in .NET we don't need an object overload, since strings are sealed anyway.
- // /**
- // * Encode the value using DoubleMetaphone. It will only work if
- // * obj
is a String
(like Metaphone
).
- // *
- // * @param obj Object to encode (should be of type String)
- // * @return An encoded Object (will be of type String)
- // * @throws EncoderException encode parameter is not of type String
- // */
-
- //public virtual object Encode(object obj)
- // {
- // if (!(obj is String)) {
- // throw new EncoderException("DoubleMetaphone encode parameter is not of type String");
- // }
- // return GetDoubleMetaphone((String) obj);
- // }
+ // LUCENENET specific - in .NET we don't need an object overload of Encode(), since strings are sealed anyway.
///
/// Encode the value using DoubleMetaphone.
///
/// String to encode.
/// An encoded string.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public virtual string Encode(string value)
{
return GetDoubleMetaphone(value);
@@ -229,6 +216,7 @@ public virtual string Encode(string value)
/// The left-hand side of the encoded .
/// The right-hand side of the encoded .
/// true if the encoded s are equal; false otherwise.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public virtual bool IsDoubleMetaphoneEqual(string value1, string value2)
{
return IsDoubleMetaphoneEqual(value1, value2, false);
@@ -242,6 +230,7 @@ public virtual bool IsDoubleMetaphoneEqual(string value1, string value2)
/// The right-hand side of the encoded .
/// Use the alternate value if true.
/// true if the encoded s are equal; false otherwise.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public virtual bool IsDoubleMetaphoneEqual(string value1, string value2, bool alternate)
{
return GetDoubleMetaphone(value1, alternate).Equals(GetDoubleMetaphone(value2, alternate), StringComparison.Ordinal);
@@ -261,6 +250,7 @@ public virtual int MaxCodeLen
///
/// Handles 'A', 'E', 'I', 'O', 'U', and 'Y' cases.
///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
private int HandleAEIOUY(DoubleMetaphoneResult result, int index)
{
if (index == 0)
@@ -382,7 +372,7 @@ private int HandleCC(string value, DoubleMetaphoneResult result, int index)
///
/// Handles 'CH' cases.
///
- private int HandleCH(string value, DoubleMetaphoneResult result, int index)
+ private static int HandleCH(string value, DoubleMetaphoneResult result, int index) // LUCENENET: CA1822: Mark members as static
{
if (index > 0 && Contains(value, index, 4, "CHAE"))
{ // Michael
@@ -1011,7 +1001,7 @@ private bool ConditionC0(string value, int index)
///
/// Complex condition 0 for 'CH'.
///
- private bool ConditionCH0(string value, int index)
+ private static bool ConditionCH0(string value, int index) // LUCENENET: CA1822: Mark members as static
{
if (index != 0)
{
@@ -1035,7 +1025,7 @@ private bool ConditionCH0(string value, int index)
///
/// Complex condition 1 for 'CH'.
///
- private bool ConditionCH1(string value, int index)
+ private static bool ConditionCH1(string value, int index) // LUCENENET: CA1822: Mark members as static
{
return ((Contains(value, 0, 4, "VAN ", "VON ") || Contains(value, 0, 3, "SCH")) ||
Contains(value, index - 2, 6, "ORCHES", "ARCHIT", "ORCHID") ||
@@ -1047,7 +1037,7 @@ private bool ConditionCH1(string value, int index)
///
/// Complex condition 0 for 'L'.
///
- private bool ConditionL0(string value, int index)
+ private static bool ConditionL0(string value, int index) // LUCENENET: CA1822: Mark members as static
{
if (index == value.Length - 3 &&
Contains(value, index - 1, 4, "ILLO", "ILLA", "ALLE"))
@@ -1085,6 +1075,7 @@ private bool ConditionM0(string value, int index)
/// Determines whether or not a value is of slavo-germanic origin. A value is
/// of slavo-germanic origin if it contians any of 'W', 'K', 'CZ', or 'WITZ'.
///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
private bool IsSlavoGermanic(string value)
{
return value.IndexOf('W') > -1 || value.IndexOf('K') > -1 ||
@@ -1094,7 +1085,8 @@ private bool IsSlavoGermanic(string value)
///
/// Determines whether or not a character is a vowel or not
///
- private bool IsVowel(char ch)
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ private static bool IsVowel(char ch) // LUCENENET: CA1822: Mark members as static
{
return VOWELS.IndexOf(ch) != -1;
}
@@ -1193,18 +1185,21 @@ public DoubleMetaphoneResult(int maxLength)
this.alternate = new StringBuilder(maxLength);
}
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public virtual void Append(char value)
{
AppendPrimary(value);
AppendAlternate(value);
}
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public virtual void Append(char primary, char alternate)
{
AppendPrimary(primary);
AppendAlternate(alternate);
}
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public virtual void AppendPrimary(char value)
{
if (this.primary.Length < this.maxLength)
@@ -1213,6 +1208,7 @@ public virtual void AppendPrimary(char value)
}
}
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public virtual void AppendAlternate(char value)
{
if (this.alternate.Length < this.maxLength)
@@ -1221,12 +1217,14 @@ public virtual void AppendAlternate(char value)
}
}
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public virtual void Append(string value)
{
AppendPrimary(value);
AppendAlternate(value);
}
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public virtual void Append(string primary, string alternate)
{
AppendPrimary(primary);
diff --git a/src/Lucene.Net.Analysis.Phonetic/Language/MatchRatingApproachEncoder.cs b/src/Lucene.Net.Analysis.Phonetic/Language/MatchRatingApproachEncoder.cs
index 4cc3b347d9..ce3ab003b5 100644
--- a/src/Lucene.Net.Analysis.Phonetic/Language/MatchRatingApproachEncoder.cs
+++ b/src/Lucene.Net.Analysis.Phonetic/Language/MatchRatingApproachEncoder.cs
@@ -98,26 +98,7 @@ internal string CleanName(string name)
return upperName;
}
- // LUCENENET specific - in .NET we don't need an object overload, since strings are sealed anyway.
- // **
- // * Encodes an Object using the Match Rating Approach algorithm. Method is here to satisfy the requirements of the
- // * Encoder interface Throws an EncoderException if input object is not of type java.lang.string.
- // *
- // * @param pObject
- // * Object to encode
- // * @return An object (or type java.lang.string) containing the Match Rating Approach code which corresponds to the
- // * string supplied.
- // * @throws EncoderException
- // * if the parameter supplied is not of type java.lang.string
- // */
- //public Object encode(Object pObject) throws EncoderException
- //{
- //if (!(pObject instanceof string)) {
- // throw new EncoderException(
- // "Parameter supplied to Match Rating Approach encoder is not of type java.lang.string");
- // }
- //return encode((string) pObject);
- //}
+ // LUCENENET specific - in .NET we don't need an object overload of Encode(), since strings are sealed anyway.
///
/// Encodes a string using the Match Rating Approach (MRA) algorithm.
@@ -178,7 +159,7 @@ internal string GetFirst3Last3(string name)
/// The min rating value.
internal int GetMinRating(int sumLength)
{
- int minRating = 0;
+ int minRating; // LUCENENET: IDE0059: Remove unnecessary value assignment
if (sumLength <= FOUR)
{
@@ -259,7 +240,7 @@ public virtual bool IsEncodeEquals(string name1, string name2)
// 5. Obtain the minimum rating value by calculating the length sum of the
// encoded strings and sending it down.
int sumLength = Math.Abs(name1.Length + name2.Length);
- int minRating = 0;
+ int minRating; // LUCENENET: IDE0059: Remove unnecessary value assignment
minRating = GetMinRating(sumLength);
// 6. Process the encoded strings from left to right and remove any
@@ -277,7 +258,7 @@ public virtual bool IsEncodeEquals(string name1, string name2)
///
/// The letter under investiagtion.
/// true if a vowel, else false.
- internal bool IsVowel(string letter)
+ internal static bool IsVowel(string letter) // LUCENENET: CA1822: Mark members as static
{
return letter.Equals("E", StringComparison.OrdinalIgnoreCase) || letter.Equals("A", StringComparison.OrdinalIgnoreCase) || letter.Equals("O", StringComparison.OrdinalIgnoreCase) ||
letter.Equals("I", StringComparison.OrdinalIgnoreCase) || letter.Equals("U", StringComparison.OrdinalIgnoreCase);
@@ -298,11 +279,11 @@ internal int LeftToRightThenRightToLeftProcessing(string name1, string name2)
int name1Size = name1.Length - 1;
int name2Size = name2.Length - 1;
- string name1LtRStart = EMPTY;
- string name1LtREnd = EMPTY;
+ string name1LtRStart/* = EMPTY*/; // LUCENENET: IDE0059: Remove unnecessary value assignment
+ string name1LtREnd/* = EMPTY*/; // LUCENENET: IDE0059: Remove unnecessary value assignment
- string name2RtLStart = EMPTY;
- string name2RtLEnd = EMPTY;
+ string name2RtLStart/* = EMPTY*/; // LUCENENET: IDE0059: Remove unnecessary value assignment
+ string name2RtLEnd/* = EMPTY*/; // LUCENENET: IDE0059: Remove unnecessary value assignment
for (int i = 0; i < name1Char.Length; i++)
{
@@ -353,7 +334,7 @@ internal int LeftToRightThenRightToLeftProcessing(string name1, string name2)
///