-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #297 from kmaddock/fast-load
Improve performance with large solutions
- Loading branch information
Showing
19 changed files
with
170 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using FineCodeCoverage.Engine.Model; | ||
using NUnit.Framework; | ||
|
||
namespace FineCodeCoverageTests | ||
{ | ||
internal class FileLineCoverage_Tests | ||
{ | ||
[TestCaseSource(nameof(Cases))] | ||
public void GetLines_Test(IEnumerable<int> lineNumbers, int startLineNumber, int endLineNumber, IEnumerable<int> expectedLineNumbers) | ||
{ | ||
var fileLineCoverage = new FileLineCoverage(); | ||
fileLineCoverage.Add("fp", lineNumbers.Select(n => new FineCodeCoverage.Engine.Cobertura.Line { Number = n })); | ||
fileLineCoverage.Completed(); | ||
|
||
var lines = fileLineCoverage.GetLines("fp", startLineNumber, endLineNumber); | ||
Assert.That(lines.Select(l => l.Number), Is.EqualTo(expectedLineNumbers)); | ||
} | ||
|
||
static object[] Cases = | ||
{ | ||
new object[] { new int[] { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}, 19, 20, new int[]{ 19,20} }, | ||
new object[] { new int[] { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}, 12, 13, new int[]{ 12,13} }, | ||
new object[] { new int[] { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}, 6, 7, new int[]{ 6,7} }, | ||
new object[] {Enumerable.Empty<int>(), 0, 4,Enumerable.Empty<int>() }, | ||
new object[] { new int[] { 3,2,1}, 0, 4, new int[]{ 1,2,3} }, | ||
new object[] { new int[] { 3,2,1}, 0, 3, new int[]{ 1,2,3} }, | ||
new object[] { new int[] { 3,2,1}, 1, 2, new int[]{ 1,2} }, | ||
new object[] { new int[] { 3,2,1}, 2, 2, new int[]{ 2} }, | ||
new object[] { new int[] { 3,2,1}, 4, 5, Enumerable.Empty<int>() } | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using FineCodeCoverage.Core.Utilities; | ||
using FineCodeCoverage.Engine.Cobertura; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace FineCodeCoverage.Engine.Model | ||
{ | ||
// FileLineCoverage maps from a filename to the list of lines in the file | ||
internal class FileLineCoverage | ||
{ | ||
private Dictionary<string, List<Line>> m_coverageLines = new Dictionary<string, List<Line>>(StringComparer.OrdinalIgnoreCase); | ||
|
||
public void Add(string filename, IEnumerable<Line> lines) | ||
{ | ||
if (!m_coverageLines.TryGetValue(filename, out var fileCoverageLines)) | ||
{ | ||
fileCoverageLines = new List<Line>(); | ||
m_coverageLines.Add(filename, fileCoverageLines); | ||
} | ||
|
||
fileCoverageLines.AddRange(lines); | ||
} | ||
|
||
public void Completed() | ||
{ | ||
foreach (var lines in m_coverageLines.Values) | ||
lines.Sort((a, b) => a.Number - b.Number); | ||
} | ||
|
||
public IEnumerable<Line> GetLines(string filePath, int startLineNumber, int endLineNumber) | ||
{ | ||
if (!m_coverageLines.TryGetValue(filePath, out var lines)) | ||
yield break; | ||
|
||
int first = lines.LowerBound(line => startLineNumber - line.Number); | ||
if (first != -1) | ||
{ | ||
for (int it = first; it < lines.Count && lines[it].Number <= endLineNumber; ++it) | ||
yield return lines[it]; | ||
} | ||
|
||
} | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace FineCodeCoverage.Core.Utilities | ||
{ | ||
public static class ListExtensions | ||
{ | ||
// To be performed on a sorted list | ||
// Returns -1 for empty list or when all elements are outside the lower bounds | ||
// Compare fn to return 0 for element considered the lower bound | ||
// > 0 for lower bound greater than element | ||
|
||
public static int LowerBound<T>(this IList<T> list, Func<T, int> compare) | ||
{ | ||
int first = 0; | ||
int count = list.Count; | ||
if (count == 0) return -1; | ||
|
||
while (count > 0) | ||
{ | ||
int step = count / 2; | ||
int index = first + step; | ||
var result = compare(list[index]); | ||
if (result == 0) | ||
{ | ||
return index; | ||
} | ||
else if (result > 0) | ||
{ | ||
first = ++index; | ||
count -= step + 1; | ||
} | ||
else | ||
{ | ||
count = step; | ||
} | ||
} | ||
|
||
return first != list.Count ? first : -1; | ||
} | ||
} | ||
} |
7 changes: 4 additions & 3 deletions
7
SharedProject/Impl/CoverageColour/GlyphMargin/CoverageLineGlyphTag.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.