Review usage of string.Substring (part 1)

Reduced allocations by replacing string.Substring with ReadOnlySpan<char>.Slice
This commit is contained in:
Bond_009
2020-07-22 13:34:51 +02:00
parent 0750357916
commit febb6bced6
25 changed files with 124 additions and 99 deletions

View File

@@ -448,21 +448,21 @@ namespace Emby.Drawing
/// or
/// filename.
/// </exception>
public string GetCachePath(string path, string filename)
public string GetCachePath(ReadOnlySpan<char> path, ReadOnlySpan<char> filename)
{
if (string.IsNullOrEmpty(path))
if (path.IsEmpty)
{
throw new ArgumentNullException(nameof(path));
throw new ArgumentException("Path can't be empty.", nameof(path));
}
if (string.IsNullOrEmpty(filename))
if (path.IsEmpty)
{
throw new ArgumentNullException(nameof(filename));
throw new ArgumentException("Filename can't be empty.", nameof(filename));
}
var prefix = filename.Substring(0, 1);
var prefix = filename.Slice(0, 1);
return Path.Combine(path, prefix, filename);
return Path.Join(path, prefix, filename);
}
/// <inheritdoc />