From 230dfd452d1d182b61fe4bbfa4dd53babf5d2f15 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 25 Sep 2013 22:01:50 -0400 Subject: [PATCH] reduce dictionary creation in xml savers --- .../Savers/XmlSaverHelpers.cs | 113 +++++++++--------- 1 file changed, 57 insertions(+), 56 deletions(-) diff --git a/MediaBrowser.Providers/Savers/XmlSaverHelpers.cs b/MediaBrowser.Providers/Savers/XmlSaverHelpers.cs index 338447c100..900e8059fb 100644 --- a/MediaBrowser.Providers/Savers/XmlSaverHelpers.cs +++ b/MediaBrowser.Providers/Savers/XmlSaverHelpers.cs @@ -18,6 +18,59 @@ namespace MediaBrowser.Providers.Savers /// public static class XmlSaverHelpers { + private static readonly Dictionary CommonTags = new[] { + + "Added", + "AspectRatio", + "BirthDate", + "Budget", + "certification", + "Chapters", + "ContentRating", + "CustomRating", + "CriticRating", + "CriticRatingSummary", + "DeathDate", + "EndDate", + "Genres", + "Genre", + "GamesDbId", + "IMDB_ID", + "IMDB", + "IMDbId", + "Language", + "LocalTitle", + "LockData", + "LockedFields", + "MediaInfo", + "MPAARating", + "MusicbrainzId", + "MusicBrainzReleaseGroupId", + "Overview", + "Persons", + "PremiereDate", + "ProductionYear", + "Rating", + "Revenue", + "RottenTomatoesId", + "RunningTime", + "Runtime", + "SortTitle", + "Studios", + "Tags", + "TagLine", + "Taglines", + "TMDbCollectionId", + "TMDbId", + "Trailer", + "TVcomId", + "TvDbId", + "Type", + "Website", + "Zap2ItId" + + }.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase); + /// /// The us culture /// @@ -33,58 +86,6 @@ namespace MediaBrowser.Providers.Savers { if (File.Exists(path)) { - xmlTagsUsed.AddRange(new[] - { - "MediaInfo", - "ContentRating", - "MPAARating", - "certification", - "Persons", - "Type", - "Overview", - "CustomRating", - "LocalTitle", - "SortTitle", - "PremiereDate", - "EndDate", - "Budget", - "Revenue", - "Rating", - "ProductionYear", - "Website", - "AspectRatio", - "Language", - "RunningTime", - "Runtime", - "TagLine", - "Taglines", - "IMDB_ID", - "IMDB", - "IMDbId", - "TMDbId", - "TVcomId", - "TvDbId", - "RottenTomatoesId", - "MusicbrainzId", - "TMDbCollectionId", - "Genres", - "Genre", - "Studios", - "Tags", - "Added", - "LockData", - "Trailer", - "CriticRating", - "CriticRatingSummary", - "GamesDbId", - "BirthDate", - "DeathDate", - "LockedFields", - "Chapters", - "MusicBrainzReleaseGroupId", - "Zap2ItId" - }); - var position = xml.ToString().LastIndexOf("The path. /// The XML tags used. /// System.String. - private static string GetCustomTags(string path, IEnumerable xmlTagsUsed) + private static string GetCustomTags(string path, List xmlTagsUsed) { var settings = new XmlReaderSettings { @@ -150,8 +151,6 @@ namespace MediaBrowser.Providers.Savers ValidationType = ValidationType.None }; - var tagsDictionary = xmlTagsUsed.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase); - var builder = new StringBuilder(); using (var streamReader = new StreamReader(path, Encoding.UTF8)) @@ -166,7 +165,9 @@ namespace MediaBrowser.Providers.Savers { if (reader.NodeType == XmlNodeType.Element) { - if (!tagsDictionary.ContainsKey(reader.Name)) + var name = reader.Name; + + if (!CommonTags.ContainsKey(name) && !xmlTagsUsed.Contains(name, StringComparer.OrdinalIgnoreCase)) { builder.AppendLine(reader.ReadOuterXml()); }