initializing stringbuilder with text instead of appending after init.

trimming end instead of both beginning and end, since we know whats in the beginning.
This commit is contained in:
Claus
2017-02-01 14:03:03 +01:00
parent 90448f1c78
commit 06c829eb27

View File

@@ -47,25 +47,21 @@ namespace Umbraco.Web.Trees
virtualPath = virtualPath.Replace('\\', '/');
//-1 is the default root id for trees
var sb = new StringBuilder();
sb.Append("-1");
var sb = new StringBuilder("-1");
//split the virtual path and iterate through it
string[] pathPaths = virtualPath.Split('/');
var pathPaths = virtualPath.Split('/');
for (int p = 0; p < pathPaths.Length; p++)
for (var p = 0; p < pathPaths.Length; p++)
{
var path = HttpUtility.UrlEncode(string.Join("/", pathPaths.Take(p + 1)));
if (string.IsNullOrEmpty(path) == false)
{
sb.Append(",");
sb.Append(path);
sb.Append(path);
}
}
return sb.ToString().Trim(",");
return sb.ToString().TrimEnd(",");
}
}
}