* decl.cs (DeclSpace.LookupType): Don't loop but recurse into
authorRaja R Harinath <harinath@hurrynot.org>
Wed, 9 Mar 2005 14:05:25 +0000 (14:05 -0000)
committerRaja R Harinath <harinath@hurrynot.org>
Wed, 9 Mar 2005 14:05:25 +0000 (14:05 -0000)
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.

Turns out that this saves a teensy amount of memory when compiling corlib.
So, given the IMHO improved readability, this is a no-brainer ;-)

  w/o patch: 119433 KB
  w/  patch: 119389 KB

svn path=/trunk/mcs/; revision=41599

mcs/mcs/ChangeLog
mcs/mcs/decl.cs

index 71db586ad686f54bd1fe56700a5717ab4fd0a064..9e9e1ad9bab5be47a4d620d1808939e9ff15062d 100644 (file)
@@ -1,3 +1,11 @@
+2005-03-09  Raja R Harinath  <rharinath@novell.com>
+
+       * 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-03-09  Raja R Harinath  <rharinath@novell.com>
 
        Clean up a few partial-class semantics.  
index 65db9a8ea8085cd5e4829868bc1cfde88b630ebc..c112f47e311d5ee73a576eebf74932c503b6a3dd 100644 (file)
@@ -812,6 +812,34 @@ namespace Mono.CSharp {
                        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.
@@ -825,56 +853,19 @@ namespace Mono.CSharp {
                        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;
                }