From df86976f01349c7d47719f5c95d85e8ef17c335d Mon Sep 17 00:00:00 2001 From: Tebjan Halm Date: Thu, 27 Jun 2013 00:55:03 +0200 Subject: [PATCH] big performance improvement (over 50%) for writing svg strings --- Source/Svg.csproj | 6 ------ Source/SvgElement.cs | 22 ++++++++++++++++------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/Source/Svg.csproj b/Source/Svg.csproj index 7704593..593dfcc 100644 --- a/Source/Svg.csproj +++ b/Source/Svg.csproj @@ -70,13 +70,7 @@ bin\Release\Svg.XML - - - - 3.5 - - diff --git a/Source/SvgElement.cs b/Source/SvgElement.cs index b660bc4..c043052 100644 --- a/Source/SvgElement.cs +++ b/Source/SvgElement.cs @@ -15,6 +15,15 @@ namespace Svg /// public abstract class SvgElement : ISvgElement, ISvgTransformable, ICloneable { + //optimization + protected class AttributeTuple + { + public PropertyDescriptor Property; + public SvgAttributeAttribute Attribute; + } + protected IEnumerable _svgAttributes; + + internal SvgElement _parent; private string _elementName; private SvgAttributeCollection _attributes; @@ -283,6 +292,12 @@ namespace Svg this._eventHandlers = new EventHandlerList(); this._elementName = string.Empty; this._customAttributes = new Dictionary(); + + //fill svg attribute description + _svgAttributes = from PropertyDescriptor a in TypeDescriptor.GetProperties(this) + let attribute = a.Attributes[typeof(SvgAttributeAttribute)] as SvgAttributeAttribute + where attribute != null + select new AttributeTuple { Property = a, Attribute = attribute }; } @@ -336,12 +351,7 @@ namespace Svg protected virtual void WriteAttributes(XmlTextWriter writer) { - var attributes = from PropertyDescriptor a in TypeDescriptor.GetProperties(this) - let attribute = a.Attributes[typeof(SvgAttributeAttribute)] as SvgAttributeAttribute - where attribute != null - select new { Property = a, Attribute = attribute }; - - foreach (var attr in attributes) + foreach (var attr in _svgAttributes) { if (attr.Property.Converter.CanConvertTo(typeof(string))) { -- GitLab