Author: martin
Date: 2005-04-13 07:41:48 -0400 (Wed, 13 Apr 2005)
New Revision: 42906

Modified:
   trunk/mcs/gmcs/ChangeLog
   trunk/mcs/gmcs/attribute.cs
Log:
**** Merged 41207 from MCS ****


Modified: trunk/mcs/gmcs/ChangeLog
===================================================================
--- trunk/mcs/gmcs/ChangeLog    2005-04-13 11:41:06 UTC (rev 42905)
+++ trunk/mcs/gmcs/ChangeLog    2005-04-13 11:41:48 UTC (rev 42906)
@@ -1,3 +1,9 @@
+2005-02-25  Marek Safar  <[EMAIL PROTECTED]>
+
+       * attribute.cs (Atttribute.Resolve): Add cache for parameter-less
+       attributes. Removed useless attribute double check.
+       It saves almost 2MBs for corlib.
+
 2005-02-25  Raja R Harinath  <[EMAIL PROTECTED]>
 
        Fix #72924.

Modified: trunk/mcs/gmcs/attribute.cs
===================================================================
--- trunk/mcs/gmcs/attribute.cs 2005-04-13 11:41:06 UTC (rev 42905)
+++ trunk/mcs/gmcs/attribute.cs 2005-04-13 11:41:48 UTC (rev 42906)
@@ -302,6 +302,9 @@
                        return false;
                }
                
+               // Cache for parameter-less attributes
+               static PtrHashtable att_cache = new PtrHashtable ();
+
                public virtual CustomAttributeBuilder Resolve (EmitContext ec)
                {
                        if (resolve_error)
@@ -309,25 +312,25 @@
 
                        resolve_error = true;
 
-                       Type oldType = Type;
-                       
-                       // Sanity check.
-                       Type = CheckAttributeType (ec); // TODO: I really don't 
think we need such expensive double check
+                       if (Type == null)
+                               Type = CheckAttributeType (ec);
 
-                       if (oldType == null && Type == null)
+                       if (Type == null)
                                return null;
-                       if (oldType != null && oldType != Type){
-                               Report.Error (-27, Location,
-                                             "Attribute {0} resolved to 
different types at different times: {1} vs. {2}",
-                                             Name, oldType, Type);
-                               return null;
-                       }
 
                        if (Type.IsAbstract) {
                                Report.Error (653, Location, "Cannot apply 
attribute class '{0}' because it is abstract", Name);
                                return null;
                        }
 
+                       if (Arguments == null) {
+                               object o = att_cache [Type];
+                               if (o != null) {
+                                       resolve_error = false;
+                                       return (CustomAttributeBuilder)o;
+                               }
+                       }
+
                        bool MethodImplAttr = false;
                        bool MarshalAsAttr = false;
                        bool GuidAttr = false;
@@ -615,9 +618,13 @@
                                                prop_info_arr, prop_values_arr,
                                                field_info_arr, 
field_values_arr);
                                }
-                               else
+                               else {
                                        cb = new CustomAttributeBuilder (
                                                (ConstructorInfo) constructor, 
pos_values);
+
+                                       if (pos_values.Length == 0)
+                                               att_cache.Add (Type, cb);
+                               }
                        } catch (Exception e) {
                                //
                                // Sample:
@@ -755,10 +762,10 @@
                                Resolve (ec);
 
                        // Some error occurred
-                       if (pos_values == null)
+                       if (resolve_error)
                                return null;
 
-                       if (pos_values.Length == 0)
+                       if (pos_values == null || pos_values.Length == 0)
                                return new ObsoleteAttribute ();
 
                        if (pos_values.Length == 1)

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to