Author: lluis
Date: 2008-02-14 20:38:48 -0500 (Thu, 14 Feb 2008)
New Revision: 95722
Modified:
trunk/monodevelop/main/src/core/MonoDevelop.Core/ChangeLog
trunk/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Core.mdp
trunk/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Core/Properties.cs
Log:
* MonoDevelop.Core/Properties.cs: Improve performance of Get method.
Modified: trunk/monodevelop/main/src/core/MonoDevelop.Core/ChangeLog
===================================================================
--- trunk/monodevelop/main/src/core/MonoDevelop.Core/ChangeLog 2008-02-15
01:32:02 UTC (rev 95721)
+++ trunk/monodevelop/main/src/core/MonoDevelop.Core/ChangeLog 2008-02-15
01:38:48 UTC (rev 95722)
@@ -1,3 +1,7 @@
+2008-02-15 Lluis Sanchez Gual <[EMAIL PROTECTED]>
+
+ * MonoDevelop.Core/Properties.cs: Improve performance of Get method.
+
2008-02-07 Michael Hutchinson <[EMAIL PROTECTED]>
* MonoDevelop.Core.Execution/ProcessWrapper.cs: Add a WaitForOutput
overload
Modified:
trunk/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Core/Properties.cs
===================================================================
---
trunk/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Core/Properties.cs
2008-02-15 01:32:02 UTC (rev 95721)
+++
trunk/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Core/Properties.cs
2008-02-15 01:38:48 UTC (rev 95722)
@@ -44,6 +44,7 @@
{
Dictionary<string, object> properties = new
Dictionary<string, object> ();
Dictionary<string, object> defaultValues = new
Dictionary<string, object> ();
+ Dictionary<Type, TypeConverter> cachedConverters = new
Dictionary<Type, TypeConverter> ();
public ICollection<string> Keys {
get {
@@ -59,8 +60,9 @@
{
if (o is T)
return (T)o;
+
+ TypeConverter converter = GetConverter (typeof(T));
- TypeConverter converter = TypeDescriptor.GetConverter
(typeof(T));
if (o is string) {
try {
return
(T)converter.ConvertFromInvariantString (o.ToString ());
@@ -80,10 +82,20 @@
{
if (o == null)
return null;
- TypeConverter converter = TypeDescriptor.GetConverter
(o.GetType ());
+ TypeConverter converter = GetConverter (o.GetType ());
return converter.ConvertToInvariantString (o);
}
+ TypeConverter GetConverter (Type type)
+ {
+ TypeConverter converter;
+ if (!cachedConverters.TryGetValue (type, out
converter)) {
+ converter = TypeDescriptor.GetConverter (type);
+ cachedConverters [type] = converter;
+ }
+ return converter;
+ }
+
public T Get<T> (string property, T defaultValue)
{
defaultValues[property] = defaultValue;
Modified: trunk/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Core.mdp
===================================================================
--- trunk/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Core.mdp
2008-02-15 01:32:02 UTC (rev 95721)
+++ trunk/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Core.mdp
2008-02-15 01:38:48 UTC (rev 95722)
@@ -106,4 +106,4 @@
<DeploymentInformation strategy="File">
<excludeFiles />
</DeploymentInformation>
-</Project>
+</Project>
\ No newline at end of file
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches