提交 394358b1 编写于 作者: P Pharring

This change introduces an overload of the LocalizableResourceString...

This change introduces an overload of the LocalizableResourceString constructor which does not take any formatting arguments.

Memspect reported over 3,000 instances of zero-length string arrays being created for constructing LocalizableResourceString.

Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.ErrorFacts.GetTitle
Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.ErrorFacts.GetDescription
Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.ErrorFacts.GetMessageFormat (changeset 1406198)
上级 2b9990ce
......@@ -18,7 +18,17 @@ public sealed class LocalizableResourceString : LocalizableString, IObjectReadab
private readonly ResourceManager _resourceManager;
private readonly Type _resourceSource;
private readonly string[] _formatArguments;
private static readonly string[] s_emptyArguments = new string[0];
/// <summary>
/// Creates a localizable resource string with no formatting arguments.
/// </summary>
/// <param name="nameOfLocalizableResource">nameof the resource that needs to be localized.</param>
/// <param name="resourceManager"><see cref="ResourceManager"/> for the calling assembly.</param>
/// <param name="resourceSource">Type handling assembly's resource management. Typically, this is the static class generated for the resources file from which resources are accessed.</param>
public LocalizableResourceString(string nameOfLocalizableResource, ResourceManager resourceManager, Type resourceSource)
: this(nameOfLocalizableResource, resourceManager, resourceSource, SpecializedCollections.EmptyArray<string>())
{
}
/// <summary>
/// Creates a localizable resource string that may possibly be formatted differently depending on culture.
......@@ -64,7 +74,7 @@ private LocalizableResourceString(ObjectReader reader)
var length = (int)reader.ReadCompressedUInt();
if (length == 0)
{
_formatArguments = s_emptyArguments;
_formatArguments = SpecializedCollections.EmptyArray<string>();
}
else
{
......
......@@ -587,6 +587,7 @@ Microsoft.CodeAnalysis.LineVisibility.BeforeFirstLineDirective = 0
Microsoft.CodeAnalysis.LineVisibility.Hidden = 1
Microsoft.CodeAnalysis.LineVisibility.Visible = 2
Microsoft.CodeAnalysis.LocalizableResourceString
Microsoft.CodeAnalysis.LocalizableResourceString.LocalizableResourceString(string nameOfLocalizableResource, System.Resources.ResourceManager resourceManager, System.Type resourceSource)
Microsoft.CodeAnalysis.LocalizableResourceString.LocalizableResourceString(string nameOfLocalizableResource, System.Resources.ResourceManager resourceManager, System.Type resourceSource, params string[] formatArguments)
Microsoft.CodeAnalysis.LocalizableString
Microsoft.CodeAnalysis.Location
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册