From 3603e43d6e10f4b6c77ba787bbb549e7db57023a Mon Sep 17 00:00:00 2001 From: Toni Solarin-Sodara Date: Fri, 10 Aug 2018 13:30:32 +0100 Subject: [PATCH] write document index to hits file instead of its path --- src/coverlet.core/Coverage.cs | 6 +----- .../Instrumentation/Instrumenter.cs | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/coverlet.core/Coverage.cs b/src/coverlet.core/Coverage.cs index f98894e18..e6750cefa 100644 --- a/src/coverlet.core/Coverage.cs +++ b/src/coverlet.core/Coverage.cs @@ -173,11 +173,7 @@ private void CalculateCoverage() continue; bool isBranch = info[0] == "B"; - - if (!result.Documents.TryGetValue(info[1], out var document)) - { - continue; - } + var document = result.Documents.ElementAt(int.Parse(info[1])).Value; int start = int.Parse(info[2]); int hits = int.Parse(info[4]); diff --git a/src/coverlet.core/Instrumentation/Instrumenter.cs b/src/coverlet.core/Instrumentation/Instrumenter.cs index 19eec24aa..5925298e9 100644 --- a/src/coverlet.core/Instrumentation/Instrumenter.cs +++ b/src/coverlet.core/Instrumentation/Instrumenter.cs @@ -175,11 +175,17 @@ private void InstrumentIL(MethodDefinition method) private Instruction AddInstrumentationCode(MethodDefinition method, ILProcessor processor, Instruction instruction, SequencePoint sequencePoint) { + int documentIndex = 0; if (!_result.Documents.TryGetValue(sequencePoint.Document.Url, out var document)) { document = new Document { Path = sequencePoint.Document.Url }; + documentIndex = _result.Documents.Count; _result.Documents.Add(document.Path, document); } + else + { + documentIndex = _result.Documents.Keys.ToList().IndexOf(document.Path); + } for (int i = sequencePoint.StartLine; i <= sequencePoint.EndLine; i++) { @@ -187,7 +193,7 @@ private Instruction AddInstrumentationCode(MethodDefinition method, ILProcessor document.Lines.Add(i, new Line { Number = i, Class = method.DeclaringType.FullName, Method = method.FullName }); } - string marker = $"L,{document.Path},{sequencePoint.StartLine},{sequencePoint.EndLine}"; + string marker = $"L,{documentIndex},{sequencePoint.StartLine},{sequencePoint.EndLine}"; var pathInstr = Instruction.Create(OpCodes.Ldstr, _result.HitsFilePath); var markInstr = Instruction.Create(OpCodes.Ldstr, marker); @@ -202,11 +208,17 @@ private Instruction AddInstrumentationCode(MethodDefinition method, ILProcessor private Instruction AddInstrumentationCode(MethodDefinition method, ILProcessor processor, Instruction instruction, BranchPoint branchPoint) { + int documentIndex = 0; if (!_result.Documents.TryGetValue(branchPoint.Document, out var document)) { document = new Document { Path = branchPoint.Document }; + documentIndex = _result.Documents.Count; _result.Documents.Add(document.Path, document); } + else + { + documentIndex = _result.Documents.Keys.ToList().IndexOf(document.Path); + } var key = (branchPoint.StartLine, (int)branchPoint.Ordinal); if (!document.Branches.ContainsKey(key)) @@ -223,7 +235,7 @@ private Instruction AddInstrumentationCode(MethodDefinition method, ILProcessor } ); - string marker = $"B,{document.Path},{branchPoint.StartLine},{branchPoint.Ordinal}"; + string marker = $"B,{documentIndex},{branchPoint.StartLine},{branchPoint.Ordinal}"; var pathInstr = Instruction.Create(OpCodes.Ldstr, _result.HitsFilePath); var markInstr = Instruction.Create(OpCodes.Ldstr, marker);