Skip to content

memory optimization for file reading #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/coverlet.core/Coverage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ private void CalculateCoverage()
{
if (!File.Exists(result.HitsFilePath)) { continue; }
var lines = InstrumentationHelper.ReadHitsFile(result.HitsFilePath);
for (int i = 0; i < lines.Length; i++)
foreach (var line in lines)
{
var info = lines[i].Split(',');
var info = line.Split(',');
// Ignore malformed lines
if (info.Length != 4)
continue;
Expand All @@ -113,11 +113,11 @@ private void CalculateCoverage()

for (int j = start; j <= end; j++)
{
var line = document.Lines.First(l => l.Number == j);
line.Hits = line.Hits + 1;
var subLine = document.Lines.First(l => l.Number == j);
subLine.Hits = subLine.Hits + 1;

if (j == start)
line.IsBranchTarget = target;
subLine.IsBranchTarget = target;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/coverlet.core/Helpers/InstrumentationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static void RestoreOriginalModule(string module, string identifier)
}, retryStrategy, 10);
}

public static string[] ReadHitsFile(string path)
public static IEnumerable<string> ReadHitsFile(string path)
{
// Retry hitting the hits file - retry up to 10 times, since the file could be locked
// See: https://github.com/tonerdo/coverlet/issues/25
Expand All @@ -90,7 +90,7 @@ public static string[] ReadHitsFile(string path)
return sleep;
};

return RetryHelper.Do(() => File.ReadAllLines(path), retryStrategy, 10);
return RetryHelper.Do(() => File.ReadLines(path), retryStrategy, 10);
}

public static void DeleteHitsFile(string path)
Expand Down