Skip to content

Commit

Permalink
Avoid unnecessary control flow
Browse files Browse the repository at this point in the history
  • Loading branch information
ds5678 authored and SamboyCoding committed Aug 18, 2024
1 parent b56f402 commit fa86c09
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
13 changes: 5 additions & 8 deletions Cpp2IL.Core/ProcessingLayers/CallAnalysisProcessingLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,29 +68,28 @@ private static void InjectAttribute(ApplicationAnalysisContext appContext)
AttributeInjectionUtils.AddZeroParameterAttribute(m, deduplicatedMethodConstructor);
}

m.Analyze();
var convertedIsil = appContext.InstructionSet.GetIsilFromMethod(m);

if (m.ConvertedIsil is { Count: 0 })
if (convertedIsil is { Count: 0 })
{
if ((m.MethodAttributes & MethodAttributes.Abstract) == 0)
{
AttributeInjectionUtils.AddZeroParameterAttribute(m, analysisNotSupportedConstructor);
}
m.ReleaseAnalysisData();
continue;
}

if (m.ConvertedIsil.Any(i => i.OpCode == InstructionSetIndependentOpCode.Invalid))
if (convertedIsil.Any(i => i.OpCode == InstructionSetIndependentOpCode.Invalid))
{
AttributeInjectionUtils.AddZeroParameterAttribute(m, invalidInstructionsConstructor);
}

if (m.ConvertedIsil.Any(i => i.OpCode == InstructionSetIndependentOpCode.NotImplemented))
if (convertedIsil.Any(i => i.OpCode == InstructionSetIndependentOpCode.NotImplemented))
{
AttributeInjectionUtils.AddZeroParameterAttribute(m, unimplementedInstructionsConstructor);
}

foreach (var instruction in m.ConvertedIsil)
foreach (var instruction in convertedIsil)
{
if (instruction.OpCode != InstructionSetIndependentOpCode.Call && instruction.OpCode != InstructionSetIndependentOpCode.CallNoReturn)
{
Expand Down Expand Up @@ -126,8 +125,6 @@ private static void InjectAttribute(ApplicationAnalysisContext appContext)
unknownCalls[m] = unknownCalls.GetOrDefault(m, 0) + 1;
}
}

m.ReleaseAnalysisData();
}

if(Cpp2IlApi.LowMemoryMode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,14 @@ private static void AnalyzeMethod(ApplicationAnalysisContext appContext, MethodA
if (m.UnderlyingPointer == 0)
return;

m.Analyze();
var convertedIsil = appContext.InstructionSet.GetIsilFromMethod(m);

if (m.ConvertedIsil is { Count: 0 })
if (convertedIsil is { Count: 0 })
{
m.ReleaseAnalysisData();
return;
}

foreach (var instruction in m.ConvertedIsil)
foreach (var instruction in convertedIsil)
{
if (instruction.OpCode == InstructionSetIndependentOpCode.Call)
{
Expand All @@ -80,8 +79,6 @@ private static void AnalyzeMethod(ApplicationAnalysisContext appContext, MethodA
}
}
}

m.ReleaseAnalysisData();
}

private static bool TryGetAddressFromInstruction(InstructionSetIndependentInstruction instruction, out ulong address)
Expand Down

0 comments on commit fa86c09

Please sign in to comment.