Skip to content

Commit

Permalink
use Span<char> instead
Browse files Browse the repository at this point in the history
  • Loading branch information
smdn committed Apr 25, 2022
1 parent b6829c8 commit b6bc804
Showing 1 changed file with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,20 @@ private static IEnumerable<KeyValuePair<string, string[]>> ReadMimeTypesFileLine

private static MimeType? FindMimeTypeByExtensionUnix(string mimeTypesFile, string extensionOrPath)
{
var extension = Path.GetExtension(extensionOrPath);
var extension = Path.GetExtension(extensionOrPath).AsSpan();

#if SYSTEM_STRING_STARTSWITH_CHAR
if (extension.StartsWith('.'))
#else
if (0 < extension.Length && extension[0] == '.')
#endif
extension = extension.Substring(1);
extension = extension.Slice(1);

if (extension.Length == 0)
if (extension.IsEmpty)
return null;

if (!File.Exists(mimeTypesFile))
throw new FileNotFoundException("Unable to read the mime.types file.", fileName: mimeTypesFile);

foreach (var entry in ReadMimeTypesFileLines(mimeTypesFile)) {
for (var index = 1; index < entry.Value.Length; index++) {
if (string.Equals(entry.Value[index], extension, StringComparison.OrdinalIgnoreCase))
if (extension.Equals(entry.Value[index].AsSpan(), StringComparison.OrdinalIgnoreCase))
return new MimeType(entry.Key);
}
}
Expand Down

0 comments on commit b6bc804

Please sign in to comment.