Skip to content

Commit

Permalink
Optimize performance of GetCountryByNameConsiderTranslation
Browse files Browse the repository at this point in the history
  • Loading branch information
tinohager committed Aug 20, 2024
1 parent 1afce7d commit e4c8350
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Nager.Country.Translation/CountryProviderExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@

namespace Nager.Country.Translation
{
/// <summary>
/// CountryProvider Extension
/// </summary>
public static class CountryProviderExtension
{
private static readonly Lazy<TranslationProvider> TranslationProvider = new Lazy<TranslationProvider>();

///<inheritdoc/>
public static ICountryInfo GetCountryByNameConsiderTranslation(
this ICountryProvider countryProvider,
Expand All @@ -24,9 +29,8 @@ public static ICountryInfo GetCountryByNameConsiderTranslation(
return country;
}

var translationProvider = new TranslationProvider();
var countryTranslation = translationProvider.GetCountryTranslation(country.Alpha2Code);
if (countryTranslation.Translations.Any(translation => translation.Name.Equals(countryName, StringComparison.OrdinalIgnoreCase)))
var countryTanslation = TranslationProvider.Value.GetCountryTranslation(country.Alpha2Code);
if (countryTanslation.Translations.Any(translation => translation.Name.Equals(countryName, StringComparison.OrdinalIgnoreCase)))
{
return country;
}
Expand Down

2 comments on commit e4c8350

@Vladilind
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Tino,
I noticed that for the PR #29 was closed and you made some minor changes directly in the main branch of that code and then closed the PR.

However, I found it a bit unusual that these minor adjustments weren't made directly in the PR itself.
Typically, it’s more common for maintainers to suggest changes so that contributors can apply them, which also helps ensure proper credit is given through the merge commit.

Best regards,
David

@tinohager
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Vladilind I had problems merging the PR because changes were not applied correctly. Since I didn't want to spend hours dealing with the Git problem, I applied the changes directly and linked the PR. You are of course right that this is not the usual way...

Please sign in to comment.