Skip to content

Potential optimizations for System.IO.Path #18223

@jamesqo

Description

@jamesqo
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

Metadata

Metadata

Assignees

Labels

area-System.IOenhancementProduct code improvement that does NOT require public API changes/additions

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions