Author: martin
Date: 2005-04-15 12:01:46 -0400 (Fri, 15 Apr 2005)
New Revision: 43054

Modified:
   trunk/mcs/gmcs/ChangeLog
   trunk/mcs/gmcs/decl.cs
Log:
**** Merged r41599 from MCS ****


Modified: trunk/mcs/gmcs/ChangeLog
===================================================================
--- trunk/mcs/gmcs/ChangeLog    2005-04-15 15:36:41 UTC (rev 43053)
+++ trunk/mcs/gmcs/ChangeLog    2005-04-15 16:01:46 UTC (rev 43054)
@@ -1,3 +1,11 @@
+2005-03-09  Raja R Harinath  <[EMAIL PROTECTED]>
+
+       * decl.cs (DeclSpace.LookupType): Don't loop but recurse into
+       enclosing DeclSpace.  This ensures that a name-lookup populates
+       more caches and there are fewer 'TypeExpression's.  Carve out
+       nested type lookup into ...
+       (LookupNestedTypeInHierarchy): ... this.
+
 2005-04-15  Martin Baulig  <[EMAIL PROTECTED]>
 
        Merged r41590 from MCS and make it work in the generics land.

Modified: trunk/mcs/gmcs/decl.cs
===================================================================
--- trunk/mcs/gmcs/decl.cs      2005-04-15 15:36:41 UTC (rev 43053)
+++ trunk/mcs/gmcs/decl.cs      2005-04-15 16:01:46 UTC (rev 43054)
@@ -959,6 +959,34 @@
                        return null;
                }
 
+               private Type LookupNestedTypeInHierarchy (string name)
+               {
+                       // if the member cache has been created, lets use it.
+                       // the member cache is MUCH faster.
+                       if (MemberCache != null)
+                               return MemberCache.FindNestedType (name);
+
+                       // no member cache. Do it the hard way -- reflection
+                       Type t = null;
+                       for (Type current_type = TypeBuilder;
+                            current_type != null && current_type != 
TypeManager.object_type;
+                            current_type = current_type.BaseType) {
+                               if (current_type is TypeBuilder) {
+                                       DeclSpace decl = this;
+                                       if (current_type != TypeBuilder)
+                                               decl = 
TypeManager.LookupDeclSpace (current_type);
+                                       t = decl.FindNestedType (name);
+                               } else {
+                                       t = TypeManager.LookupTypeDirect 
(current_type.FullName + "+" + name);
+                               }
+
+                               if (t != null && CheckAccessLevel (t))
+                                       return t;
+                       }
+
+                       return null;
+               }
+
                //
                // Public function used to locate types, this can only
                // be used after the ResolveTree function has been invoked.
@@ -972,56 +1000,19 @@
                        if (this is PartialContainer)
                                throw new InternalErrorException ("Should not 
get here");
 
-                       FullNamedExpression e;
+                       if (Cache.Contains (name))
+                               return (FullNamedExpression) Cache [name];
 
-                       if (Cache.Contains (name)) {
-                               e = (FullNamedExpression) Cache [name];
-                       } else {
-                               //
-                               // For the case the type we are looking for is 
nested within this one
-                               // or is in any base class
-                               //
-
-                               Type t = null;
-                               for (DeclSpace containing_ds = this; 
containing_ds != null; containing_ds = containing_ds.Parent) {
-                                       // if the member cache has been 
created, lets use it.
-                                       // the member cache is MUCH faster.
-                                       if (containing_ds.MemberCache != null) {
-                                               t = 
containing_ds.MemberCache.FindNestedType (name);
-                                               if (t == null)
-                                                       continue;
-
-                                               e = new TypeExpression (t, 
Location.Null);
-                                               Cache [name] = e;
-                                               return e;
-                                       }
-                                       
-                                       // no member cache. Do it the hard way 
-- reflection
-                                       for (Type current_type = 
containing_ds.TypeBuilder;
-                                            current_type != null && 
current_type != TypeManager.object_type;
-                                            current_type = 
current_type.BaseType) {
-                                               if (current_type is 
TypeBuilder) {
-                                                       DeclSpace decl = 
containing_ds;
-                                                       if (current_type != 
containing_ds.TypeBuilder)
-                                                               decl = 
TypeManager.LookupDeclSpace (current_type);
-
-                                                       t = decl.FindNestedType 
(name);
-                                               } else {
-                                                       t = 
TypeManager.LookupTypeDirect (current_type.FullName + "+" + name);
-                                               }
-
-                                               if (t != null && 
containing_ds.CheckAccessLevel (t)) {
-                                                       e = new TypeExpression 
(t, Location.Null);
-                                                       Cache [name] = e;
-                                                       return e;
-                                               }
-                                       }
-                               }
-                               
+                       FullNamedExpression e;
+                       Type t = LookupNestedTypeInHierarchy (name);
+                       if (t != null)
+                               e = new TypeExpression (t, Location.Null);
+                       else if (Parent != null && Parent != 
RootContext.Tree.Types)
+                               e = Parent.LookupType (name, loc, 
ignore_cs0104);
+                       else
                                e = NamespaceEntry.LookupNamespaceOrType (this, 
name, loc, ignore_cs0104);
-                               Cache [name] = e;
-                       }
 
+                       Cache [name] = e;
                        return e;
                }
 

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

Reply via email to