Skip to content
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

dumpnef performance #1201

Merged
merged 2 commits into from
Oct 10, 2024
Merged
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
15 changes: 8 additions & 7 deletions src/Neo.Compiler.CSharp/Optimizer/DumpNef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ public static List<int> OpCodeAddressesInMethod(NefFile nef, JToken DebugInfo, s
public static string GenerateDumpNef(NefFile nef, JToken? debugInfo)
{
Script script = nef.Script;
string addressPadding = script.GetInstructionAddressPadding();
List<(int, Instruction)> addressAndInstructionsList = script.EnumerateInstructions().ToList();
Dictionary<int, Instruction> addressToInstruction = new();
foreach ((int a, Instruction i) in addressAndInstructionsList)
Expand Down Expand Up @@ -292,13 +293,13 @@ public static string GenerateDumpNef(NefFile nef, JToken? debugInfo)
}

Dictionary<string, string[]> docPathToContent = new();
string dumpnef = "";
StringBuilder dumpnef = new();
foreach ((int a, Instruction i) in script.EnumerateInstructions(/*print: true*/).ToList())
{
if (methodStartAddrToName.ContainsKey(a))
dumpnef += $"# Method Start {methodStartAddrToName[a]}\n";
dumpnef.AppendLine($"# Method Start {methodStartAddrToName[a]}");
if (methodEndAddrToName.ContainsKey(a))
dumpnef += $"# Method End {methodEndAddrToName[a]}\n";
dumpnef.AppendLine($"# Method End {methodEndAddrToName[a]}");
if (newAddrToSequencePoint.ContainsKey(a))
{
foreach ((int docId, int startLine, int startCol, int endLine, int endCol) in newAddrToSequencePoint[a])
Expand All @@ -309,7 +310,7 @@ public static string GenerateDumpNef(NefFile nef, JToken? debugInfo)
if (!docPathToContent.ContainsKey(docPath))
docPathToContent.Add(docPath, File.ReadAllLines(docPath).ToArray());
if (startLine == endLine)
dumpnef += $"# Code {Path.GetFileName(docPath)} line {startLine}: \"{docPathToContent[docPath][startLine - 1][(startCol - 1)..(endCol - 1)]}\"\n";
dumpnef.AppendLine($"# Code {Path.GetFileName(docPath)} line {startLine}: \"{docPathToContent[docPath][startLine - 1][(startCol - 1)..(endCol - 1)]}\"");
else
for (int lineIndex = startLine; lineIndex <= endLine; lineIndex++)
{
Expand All @@ -320,14 +321,14 @@ public static string GenerateDumpNef(NefFile nef, JToken? debugInfo)
src = docPathToContent[docPath][lineIndex - 1][..(endCol - 1)].Trim();
else
src = docPathToContent[docPath][lineIndex - 1].Trim();
dumpnef += $"# Code {Path.GetFileName(docPath)} line {startLine}: \"{src}\"\n";
dumpnef.AppendLine($"# Code {Path.GetFileName(docPath)} line {startLine}: \"{src}\"");
}
}
}
if (a < script.Length)
dumpnef += $"{WriteInstruction(a, script.GetInstruction(a), script.GetInstructionAddressPadding(), nef.Tokens)}\n";
dumpnef.AppendLine($"{WriteInstruction(a, script.GetInstruction(a), addressPadding, nef.Tokens)}");
}
return dumpnef;
return dumpnef.ToString();
}
}
}
Loading