Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve perf of IsUncountable #1312

Merged
merged 1 commit into from
Feb 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/Humanizer/Inflections/Vocabulary.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace Humanizer.Inflections
Expand All @@ -16,7 +17,7 @@ internal Vocabulary()

private readonly List<Rule> _plurals = new List<Rule>();
private readonly List<Rule> _singulars = new List<Rule>();
private readonly List<string> _uncountables = new List<string>();
private readonly HashSet<string> _uncountables = new(StringComparer.CurrentCultureIgnoreCase);
private readonly Regex _letterS = new Regex("^([sS])[sS]*$");

/// <summary>
Expand Down Expand Up @@ -45,7 +46,7 @@ public void AddIrregular(string singular, string plural, bool matchEnding = true
/// <param name="word">Word to be added to the list of uncountables.</param>
public void AddUncountable(string word)
{
_uncountables.Add(word.ToLower());
_uncountables.Add(word);
}

/// <summary>
Expand Down Expand Up @@ -163,7 +164,7 @@ private string ApplyRules(IList<Rule> rules, string word, bool skipFirstRule)

private bool IsUncountable(string word)
{
return _uncountables.Contains(word.ToLower());
return _uncountables.Contains(word);
}

private string MatchUpperCase(string word, string replacement)
Expand Down