Avoid StringBuilder allocations

This commit is contained in:
Alex Barney 2018-06-29 16:07:19 -05:00
parent b6cac8b5f2
commit 16405583ce

View file

@ -104,19 +104,27 @@ namespace libhac
private void ResolveFilenames() private void ResolveFilenames()
{ {
var list = new List<string>();
var sb = new StringBuilder(); var sb = new StringBuilder();
var delimiter = "/";
foreach (var file in Files) foreach (var file in Files)
{ {
sb.Append(file.Name); list.Add(file.Name);
var dir = file.ParentDir; var dir = file.ParentDir;
while (dir != null) while (dir != null)
{ {
sb.Insert(0, "/"); list.Add(delimiter);
sb.Insert(0, dir.Name); list.Add(dir.Name);
dir = dir.Parent; dir = dir.Parent;
} }
for (int i = list.Count-1; i >= 0; i--)
{
sb.Append(list[i]);
}
file.FullPath = sb.ToString(); file.FullPath = sb.ToString();
list.Clear();
sb.Clear(); sb.Clear();
} }
} }