internal static void CheckInvalidPathChars(string path)
{
if (path == null)
ThrowArgumentNullPath();
if (PathInternal.HasIllegalCharacters(path))
ThrowArgumentInvalidPathChars();
}
- StringBuilder's indexer is not inlined, so this is very slow, although it does avoid allocations. It may be worth seeing how all of the method calls stack up against using
ToString and indexing into that instead.
- This is definitely suboptimal; I don't think
StringBuilder.Append(char) is inlined, and we could use a char[] instead since we know the max length of the buffer in advance.
- Same here
- Same here
- Maybe this could make use of
ArrayPool<char>.Shared.Rent, instead of using StringBuilder?
- Same here
cc @JeremyKuhne
CheckInvalidPathCharsis called as much as 1-3 times in most Path chars, however due to all of the exception-throwing code it doesn't look as if it's going to be inlined. SInce Do not inline methods that never return coreclr#6103 was merged, it may be beneficial to separate the throwing logic out to encourage inlining, for example:ToStringand indexing into that instead.StringBuilder.Append(char)is inlined, and we could use achar[]instead since we know the max length of the buffer in advance.ArrayPool<char>.Shared.Rent, instead of usingStringBuilder?cc @JeremyKuhne