From c39f550ed3b68bfb304cc3f729233428f48f5f1a Mon Sep 17 00:00:00 2001 From: Daniel Gut Date: Fri, 20 Apr 2018 15:03:23 +0200 Subject: [PATCH] memory optimization for file reading --- src/coverlet.core/Coverage.cs | 10 +++++----- src/coverlet.core/Helpers/InstrumentationHelper.cs | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/coverlet.core/Coverage.cs b/src/coverlet.core/Coverage.cs index 655a98dc9..10ceccab6 100644 --- a/src/coverlet.core/Coverage.cs +++ b/src/coverlet.core/Coverage.cs @@ -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; @@ -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; } } diff --git a/src/coverlet.core/Helpers/InstrumentationHelper.cs b/src/coverlet.core/Helpers/InstrumentationHelper.cs index b17eb44aa..f88af5922 100644 --- a/src/coverlet.core/Helpers/InstrumentationHelper.cs +++ b/src/coverlet.core/Helpers/InstrumentationHelper.cs @@ -78,7 +78,7 @@ public static void RestoreOriginalModule(string module, string identifier) }, retryStrategy, 10); } - public static string[] ReadHitsFile(string path) + public static IEnumerable 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 @@ -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)