Skip to content

Commit

Permalink
Reuse fileRegionsCache (#2263)
Browse files Browse the repository at this point in the history
  • Loading branch information
eddynaka committed Jan 25, 2021
1 parent 68d28e6 commit df39327
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/Sarif/FileRegionsCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace Microsoft.CodeAnalysis.Sarif
/// </summary>
public class FileRegionsCache
{
public static readonly FileRegionsCache Instance = new FileRegionsCache();
public const int DefaultCacheCapacity = 100;
private readonly IFileSystem _fileSystem;
private readonly Cache<string, Tuple<string, NewLineIndex>> _cache;
Expand Down
4 changes: 1 addition & 3 deletions src/Sarif/Visitors/InsertOptionalDataVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public override PhysicalLocation VisitPhysicalLocation(PhysicalLocation node)
Region expandedRegion;
ArtifactLocation artifactLocation = node.ArtifactLocation;

_fileRegionsCache ??= new FileRegionsCache();
_fileRegionsCache ??= FileRegionsCache.Instance;

if (artifactLocation.Uri == null && artifactLocation.Index >= 0)
{
Expand All @@ -117,8 +117,6 @@ public override PhysicalLocation VisitPhysicalLocation(PhysicalLocation node)
resolvedUri = artifactLocation.Uri;
}

if (!resolvedUri.IsAbsoluteUri) { goto Exit; }

expandedRegion = _fileRegionsCache.PopulateTextRegionProperties(node.Region, resolvedUri, populateSnippet: insertRegionSnippets);

ArtifactContent originalSnippet = node.Region.Snippet;
Expand Down

0 comments on commit df39327

Please sign in to comment.