Skip to content

Commit

Permalink
Merge pull request #6562 from dotnet/charArrayAllocs
Browse files Browse the repository at this point in the history
Reduce allocations more in public api analyzer
  • Loading branch information
CyrusNajmabadi authored Mar 31, 2023
2 parents 9a0d72e + 20ae623 commit 916b9a6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ string getApiString(ISymbol symbol, SymbolDisplayFormat format)

private static bool ContainsPublicApiName(string apiLineText, string publicApiNameToSearch)
{
apiLineText = apiLineText.Trim(ObliviousMarker);
apiLineText = apiLineText.TrimStart(ObliviousMarkerArray);

// Ensure we don't search in parameter list/return type.
var indexOfParamsList = apiLineText.IndexOf('(');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public sealed partial class DeclarePublicApiAnalyzer : DiagnosticAnalyzer
internal const string FileName = "FileName";

private const char ObliviousMarker = '~';
private static readonly char[] ObliviousMarkerArray = { ObliviousMarker };

/// <summary>
/// Boolean option to configure if public API analyzer should bail out silently if public API files are missing.
Expand Down Expand Up @@ -397,7 +398,7 @@ private static bool ValidateApiFiles(ApiData shippedData, ApiData unshippedData,
errors.Add(Diagnostic.Create(descriptor, Location.None, InvalidReasonMisplacedNullableEnable));
}

var publicApiMap = new Dictionary<string, ApiLine>(StringComparer.Ordinal);
using var publicApiMap = PooledDictionary<string, ApiLine>.GetInstance(StringComparer.Ordinal);
ValidateApiList(publicApiMap, shippedData.ApiList, isPublic, errors);
ValidateApiList(publicApiMap, unshippedData.ApiList, isPublic, errors);

Expand All @@ -408,7 +409,7 @@ private static void ValidateApiList(Dictionary<string, ApiLine> publicApiMap, Im
{
foreach (ApiLine cur in apiList)
{
string textWithoutOblivious = cur.Text.TrimStart(ObliviousMarker);
string textWithoutOblivious = cur.Text.TrimStart(ObliviousMarkerArray);
if (publicApiMap.TryGetValue(textWithoutOblivious, out ApiLine existingLine))
{
LinePositionSpan existingLinePositionSpan = existingLine.SourceText.Lines.GetLinePositionSpan(existingLine.Span);
Expand Down

0 comments on commit 916b9a6

Please sign in to comment.