Switch to using spans for string comparison

This commit is contained in:
Joe Rogers 2022-03-04 15:58:01 +01:00
parent 3205e97e1e
commit dad7a6fdf6
No known key found for this signature in database
GPG Key ID: 0074AD57B8FDBBB4

View File

@ -149,8 +149,6 @@ namespace MediaBrowser.Providers.MediaInfo
return Array.Empty<ExternalPathParserResult>();
}
var externalPathInfos = new List<ExternalPathParserResult>();
var files = directoryService.GetFilePaths(folder, clearCache).ToList();
var internalMetadataPath = video.GetInternalMetadataPath();
if (_fileSystem.DirectoryExists(internalMetadataPath))
@ -163,14 +161,15 @@ namespace MediaBrowser.Providers.MediaInfo
return Array.Empty<ExternalPathParserResult>();
}
var externalPathInfos = new List<ExternalPathParserResult>();
ReadOnlySpan<char> prefix = video.FileNameWithoutExtension;
foreach (var file in files)
{
var prefixLength = video.FileNameWithoutExtension.Length;
var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(file);
if (video.FileNameWithoutExtension.Equals(fileNameWithoutExtension[..prefixLength], StringComparison.OrdinalIgnoreCase)
&& (fileNameWithoutExtension.Length == prefixLength || _namingOptions.MediaFlagDelimiters.Contains(fileNameWithoutExtension[prefixLength])))
var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(file.AsSpan());
if (prefix.Equals(fileNameWithoutExtension[..prefix.Length], StringComparison.OrdinalIgnoreCase)
&& (fileNameWithoutExtension.Length == prefix.Length || _namingOptions.MediaFlagDelimiters.Contains(fileNameWithoutExtension[prefix.Length])))
{
var externalPathInfo = _externalPathParser.ParseFile(file, fileNameWithoutExtension[prefixLength..]);
var externalPathInfo = _externalPathParser.ParseFile(file, fileNameWithoutExtension[prefix.Length..].ToString());
if (externalPathInfo != null)
{