Browse Source

performance++

Claus Vium 3 years ago
parent
commit
065d3fa837

+ 15 - 8
Emby.Server.Implementations/Library/PathExtensions.cs

@@ -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 + "=";
-            int start = str.IndexOf(srch, StringComparison.OrdinalIgnoreCase);
-            if (start != -1)
+            var openBracketIndex = str.IndexOf('[');
+            var equalsIndex = str.IndexOf('=');
+            var closingBracketIndex = str.IndexOf(']');
+            while (openBracketIndex < equalsIndex && equalsIndex < closingBracketIndex)
             {
             {
-                start += srch.Length;
-                int end = str.IndexOf(']', start);
-                return str.Substring(start, end - start);
+                if (str[(openBracketIndex + 1)..equalsIndex].Equals(attribute, StringComparison.OrdinalIgnoreCase))
+                {
+                    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;

+ 1 - 1
Emby.Server.Implementations/Library/Resolvers/Movies/BoxSetResolver.cs

@@ -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");
 
 

+ 3 - 3
Emby.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs

@@ -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))
                     {
                     {

+ 1 - 1
Emby.Server.Implementations/Library/Resolvers/TV/SeriesResolver.cs

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