performance++

This commit is contained in:
Claus Vium 2021-11-27 16:10:43 -07:00 committed by Cody Robibero
parent 4890454935
commit 065d3fa837
4 changed files with 20 additions and 13 deletions

View file

@ -16,7 +16,7 @@ namespace Emby.Server.Implementations.Library
/// <param name="attribute">The attrib.</param> /// <param name="attribute">The attrib.</param>
/// <returns>System.String.</returns> /// <returns>System.String.</returns>
/// <exception cref="ArgumentException"><paramref name="str" /> or <paramref name="attribute" /> is empty.</exception> /// <exception cref="ArgumentException"><paramref name="str" /> or <paramref name="attribute" /> is empty.</exception>
public static string? GetAttributeValue(this string str, string attribute) public static string? GetAttributeValue(this ReadOnlySpan<char> str, ReadOnlySpan<char> attribute)
{ {
if (str.Length == 0) if (str.Length == 0)
{ {
@ -28,17 +28,24 @@ namespace Emby.Server.Implementations.Library
throw new ArgumentException("String can't be empty.", nameof(attribute)); throw new ArgumentException("String can't be empty.", nameof(attribute));
} }
string srch = "[" + attribute + "="; var openBracketIndex = str.IndexOf('[');
int start = str.IndexOf(srch, StringComparison.OrdinalIgnoreCase); var equalsIndex = str.IndexOf('=');
if (start != -1) var closingBracketIndex = str.IndexOf(']');
while (openBracketIndex < equalsIndex && equalsIndex < closingBracketIndex)
{ {
start += srch.Length; if (str[(openBracketIndex + 1)..equalsIndex].Equals(attribute, StringComparison.OrdinalIgnoreCase))
int end = str.IndexOf(']', start); {
return str.Substring(start, end - start); return str[(equalsIndex + 1)..closingBracketIndex].Trim().ToString();
}
str = str[(closingBracketIndex+ 1)..];
openBracketIndex = str.IndexOf('[');
equalsIndex = str.IndexOf('=');
closingBracketIndex = str.IndexOf(']');
} }
// for imdbid we also accept pattern matching // for imdbid we also accept pattern matching
if (string.Equals(attribute, "imdbid", StringComparison.OrdinalIgnoreCase)) if (attribute.Equals("imdbid", StringComparison.OrdinalIgnoreCase))
{ {
var match = ProviderIdParsers.TryFindImdbId(str, out var imdbId); var match = ProviderIdParsers.TryFindImdbId(str, out var imdbId);
return match ? imdbId.ToString() : null; return match ? imdbId.ToString() : null;

View file

@ -65,7 +65,7 @@ namespace Emby.Server.Implementations.Library.Resolvers.Movies
private static void SetProviderIdFromPath(BaseItem item) private static void SetProviderIdFromPath(BaseItem item)
{ {
// we need to only look at the name of this actual item (not parents) // we need to only look at the name of this actual item (not parents)
var justName = Path.GetFileName(item.Path); var justName = Path.GetFileName(item.Path.AsSpan());
var id = justName.GetAttributeValue("tmdbid"); var id = justName.GetAttributeValue("tmdbid");

View file

@ -342,9 +342,9 @@ namespace Emby.Server.Implementations.Library.Resolvers.Movies
if (item is Movie || item is MusicVideo) if (item is Movie || item is MusicVideo)
{ {
// We need to only look at the name of this actual item (not parents) // We need to only look at the name of this actual item (not parents)
var justName = item.IsInMixedFolder ? Path.GetFileName(item.Path) : Path.GetFileName(item.ContainingFolderPath); var justName = item.IsInMixedFolder ? Path.GetFileName(item.Path.AsSpan()) : Path.GetFileName(item.ContainingFolderPath.AsSpan());
if (!string.IsNullOrEmpty(justName)) if (!justName.IsEmpty)
{ {
// check for tmdb id // check for tmdb id
var tmdbid = justName.GetAttributeValue("tmdbid"); var tmdbid = justName.GetAttributeValue("tmdbid");
@ -358,7 +358,7 @@ namespace Emby.Server.Implementations.Library.Resolvers.Movies
if (!string.IsNullOrEmpty(item.Path)) if (!string.IsNullOrEmpty(item.Path))
{ {
// check for imdb id - we use full media path, as we can assume, that this will match in any use case (wither id in parent dir or in file name) // check for imdb id - we use full media path, as we can assume, that this will match in any use case (wither id in parent dir or in file name)
var imdbid = item.Path.GetAttributeValue("imdbid"); var imdbid = item.Path.AsSpan().GetAttributeValue("imdbid");
if (!string.IsNullOrWhiteSpace(imdbid)) if (!string.IsNullOrWhiteSpace(imdbid))
{ {

View file

@ -185,7 +185,7 @@ namespace Emby.Server.Implementations.Library.Resolvers.TV
/// <param name="path">The path.</param> /// <param name="path">The path.</param>
private static void SetProviderIdFromPath(Series item, string path) private static void SetProviderIdFromPath(Series item, string path)
{ {
var justName = Path.GetFileName(path); var justName = Path.GetFileName(path.AsSpan());
var tvdbId = justName.GetAttributeValue("tvdbid"); var tvdbId = justName.GetAttributeValue("tvdbid");
if (!string.IsNullOrEmpty(tvdbId)) if (!string.IsNullOrEmpty(tvdbId))