reduce dictionary creation in xml savers

pull/702/head
Luke Pulverenti 11 years ago
parent 3528d01fdb
commit 230dfd452d

@ -18,6 +18,59 @@ namespace MediaBrowser.Providers.Savers
/// </summary> /// </summary>
public static class XmlSaverHelpers public static class XmlSaverHelpers
{ {
private static readonly Dictionary<string, string> 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);
/// <summary> /// <summary>
/// The us culture /// The us culture
/// </summary> /// </summary>
@ -33,58 +86,6 @@ namespace MediaBrowser.Providers.Savers
{ {
if (File.Exists(path)) 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("</", StringComparison.OrdinalIgnoreCase); var position = xml.ToString().LastIndexOf("</", StringComparison.OrdinalIgnoreCase);
xml.Insert(position, GetCustomTags(path, xmlTagsUsed)); xml.Insert(position, GetCustomTags(path, xmlTagsUsed));
} }
@ -140,7 +141,7 @@ namespace MediaBrowser.Providers.Savers
/// <param name="path">The path.</param> /// <param name="path">The path.</param>
/// <param name="xmlTagsUsed">The XML tags used.</param> /// <param name="xmlTagsUsed">The XML tags used.</param>
/// <returns>System.String.</returns> /// <returns>System.String.</returns>
private static string GetCustomTags(string path, IEnumerable<string> xmlTagsUsed) private static string GetCustomTags(string path, List<string> xmlTagsUsed)
{ {
var settings = new XmlReaderSettings var settings = new XmlReaderSettings
{ {
@ -150,8 +151,6 @@ namespace MediaBrowser.Providers.Savers
ValidationType = ValidationType.None ValidationType = ValidationType.None
}; };
var tagsDictionary = xmlTagsUsed.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
var builder = new StringBuilder(); var builder = new StringBuilder();
using (var streamReader = new StreamReader(path, Encoding.UTF8)) using (var streamReader = new StreamReader(path, Encoding.UTF8))
@ -166,7 +165,9 @@ namespace MediaBrowser.Providers.Savers
{ {
if (reader.NodeType == XmlNodeType.Element) 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()); builder.AppendLine(reader.ReadOuterXml());
} }

Loading…
Cancel
Save