Skip to content

Commit

Permalink
Separate GetResourceString method with defaultString value. (dotnet#5…
Browse files Browse the repository at this point in the history
…1073)

It's not used in Release build and it injects ununsed null value to every callsite
  • Loading branch information
marek-safar authored Apr 13, 2021
1 parent b1f7ca4 commit 5a3da7d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
16 changes: 9 additions & 7 deletions src/libraries/Common/src/System/SR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ private static bool UsingResourceKeys() =>
false;
#endif

internal static string GetResourceString(string resourceKey, string? defaultString = null)
internal static string GetResourceString(string resourceKey)
{
if (UsingResourceKeys())
{
return defaultString ?? resourceKey;
return resourceKey;
}

string? resourceString = null;
Expand All @@ -42,14 +42,16 @@ internal static string GetResourceString(string resourceKey, string? defaultStri
}
catch (MissingManifestResourceException) { }

if (defaultString != null && resourceKey.Equals(resourceString))
{
return defaultString;
}

return resourceString!; // only null if missing resources
}

internal static string GetResourceString(string resourceKey, string defaultString)
{
string resourceString = GetResourceString(resourceKey);

return resourceKey == resourceString || resourceString == null ? defaultString : resourceString;
}

internal static string Format(string resourceFormat, object? p1)
{
if (UsingResourceKeys())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public override bool Equals(object? obj) =>
/// <summary>
/// Looks up the localized name of a given category.
/// </summary>
protected virtual string? GetLocalizedString(string value) => SR.GetResourceString("PropertyCategory" + value, null);
protected virtual string? GetLocalizedString(string value) => SR.GetResourceString("PropertyCategory" + value);

public override bool IsDefaultAttribute() => Category == Default.Category;
}
Expand Down
6 changes: 0 additions & 6 deletions src/libraries/System.Private.CoreLib/src/System/SR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ internal static partial class SR
private static int _infinitelyRecursingCount;
private static bool _resourceManagerInited;

// Needed for debugger integration
internal static string GetResourceString(string resourceKey)
{
return GetResourceString(resourceKey, null);
}

private static string InternalGetResourceString(string key)
{
if (key.Length == 0)
Expand Down

0 comments on commit 5a3da7d

Please sign in to comment.