X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FIKVM.Reflection%2FReader%2FTypeDefImpl.cs;h=b04ecbc37f211ddc32c13929a9a54ea9d937f8dd;hb=57d05a2378114770c92d0c8619153b4df01478d3;hp=fbfb2eb4af5f3e0388af26987f1c3ca5ecfd055a;hpb=63604879cc60782a4533120a9cc581c1f16dc781;p=mono.git diff --git a/mcs/class/IKVM.Reflection/Reader/TypeDefImpl.cs b/mcs/class/IKVM.Reflection/Reader/TypeDefImpl.cs index fbfb2eb4af5..b04ecbc37f2 100644 --- a/mcs/class/IKVM.Reflection/Reader/TypeDefImpl.cs +++ b/mcs/class/IKVM.Reflection/Reader/TypeDefImpl.cs @@ -66,31 +66,26 @@ namespace IKVM.Reflection.Reader public override EventInfo[] __GetDeclaredEvents() { - int token = this.MetadataToken; - // TODO use binary search? - for (int i = 0; i < module.EventMap.records.Length; i++) + foreach (int i in module.EventMap.Filter(this.MetadataToken)) { - if (module.EventMap.records[i].Parent == token) + int evt = module.EventMap.records[i].EventList - 1; + int end = module.EventMap.records.Length > i + 1 ? module.EventMap.records[i + 1].EventList - 1 : module.Event.records.Length; + EventInfo[] events = new EventInfo[end - evt]; + if (module.EventPtr.RowCount == 0) { - int evt = module.EventMap.records[i].EventList - 1; - int end = module.EventMap.records.Length > i + 1 ? module.EventMap.records[i + 1].EventList - 1 : module.Event.records.Length; - EventInfo[] events = new EventInfo[end - evt]; - if (module.EventPtr.RowCount == 0) + for (int j = 0; evt < end; evt++, j++) { - for (int j = 0; evt < end; evt++, j++) - { - events[j] = new EventInfoImpl(module, this, evt); - } + events[j] = new EventInfoImpl(module, this, evt); } - else + } + else + { + for (int j = 0; evt < end; evt++, j++) { - for (int j = 0; evt < end; evt++, j++) - { - events[j] = new EventInfoImpl(module, this, module.EventPtr.records[evt] - 1); - } + events[j] = new EventInfoImpl(module, this, module.EventPtr.records[evt] - 1); } - return events; } + return events; } return Empty.Array; } @@ -119,19 +114,14 @@ namespace IKVM.Reflection.Reader public override Type[] __GetDeclaredInterfaces() { - int token = this.MetadataToken; List list = null; - // TODO use binary search? - for (int i = 0; i < module.InterfaceImpl.records.Length; i++) + foreach (int i in module.InterfaceImpl.Filter(this.MetadataToken)) { - if (module.InterfaceImpl.records[i].Class == token) + if (list == null) { - if (list == null) - { - list = new List(); - } - list.Add(module.ResolveType(module.InterfaceImpl.records[i].Interface, this)); + list = new List(); } + list.Add(module.ResolveType(module.InterfaceImpl.records[i].Interface, this)); } return Util.ToArray(list, Type.EmptyTypes); } @@ -160,25 +150,21 @@ namespace IKVM.Reflection.Reader public override __MethodImplMap __GetMethodImplMap() { + PopulateGenericArguments(); List bodies = new List(); List> declarations = new List>(); - int token = this.MetadataToken; - // TODO use binary search? - for (int i = 0; i < module.MethodImpl.records.Length; i++) + foreach (int i in module.MethodImpl.Filter(this.MetadataToken)) { - if (module.MethodImpl.records[i].Class == token) + MethodInfo body = (MethodInfo)module.ResolveMethod(module.MethodImpl.records[i].MethodBody, typeArgs, null); + int index = bodies.IndexOf(body); + if (index == -1) { - MethodInfo body = (MethodInfo)module.ResolveMethod(module.MethodImpl.records[i].MethodBody, typeArgs, null); - int index = bodies.IndexOf(body); - if (index == -1) - { - index = bodies.Count; - bodies.Add(body); - declarations.Add(new List()); - } - MethodInfo declaration = (MethodInfo)module.ResolveMethod(module.MethodImpl.records[i].MethodDeclaration, typeArgs, null); - declarations[index].Add(declaration); + index = bodies.Count; + bodies.Add(body); + declarations.Add(new List()); } + MethodInfo declaration = (MethodInfo)module.ResolveMethod(module.MethodImpl.records[i].MethodDeclaration, typeArgs, null); + declarations[index].Add(declaration); } __MethodImplMap map = new __MethodImplMap(); map.TargetType = this; @@ -195,7 +181,7 @@ namespace IKVM.Reflection.Reader { int token = this.MetadataToken; List list = new List(); - // TODO use binary search? + // note that the NestedClass table is sorted on NestedClass, so we can't use binary search for (int i = 0; i < module.NestedClass.records.Length; i++) { if (module.NestedClass.records[i].EnclosingClass == token) @@ -208,31 +194,26 @@ namespace IKVM.Reflection.Reader public override PropertyInfo[] __GetDeclaredProperties() { - int token = this.MetadataToken; - // TODO use binary search? - for (int i = 0; i < module.PropertyMap.records.Length; i++) + foreach (int i in module.PropertyMap.Filter(this.MetadataToken)) { - if (module.PropertyMap.records[i].Parent == token) + int property = module.PropertyMap.records[i].PropertyList - 1; + int end = module.PropertyMap.records.Length > i + 1 ? module.PropertyMap.records[i + 1].PropertyList - 1 : module.Property.records.Length; + PropertyInfo[] properties = new PropertyInfo[end - property]; + if (module.PropertyPtr.RowCount == 0) { - int property = module.PropertyMap.records[i].PropertyList - 1; - int end = module.PropertyMap.records.Length > i + 1 ? module.PropertyMap.records[i + 1].PropertyList - 1 : module.Property.records.Length; - PropertyInfo[] properties = new PropertyInfo[end - property]; - if (module.PropertyPtr.RowCount == 0) + for (int j = 0; property < end; property++, j++) { - for (int j = 0; property < end; property++, j++) - { - properties[j] = new PropertyInfoImpl(module, this, property); - } + properties[j] = new PropertyInfoImpl(module, this, property); } - else + } + else + { + for (int j = 0; property < end; property++, j++) { - for (int j = 0; property < end; property++, j++) - { - properties[j] = new PropertyInfoImpl(module, this, module.PropertyPtr.records[property] - 1); - } + properties[j] = new PropertyInfoImpl(module, this, module.PropertyPtr.records[property] - 1); } - return properties; } + return properties; } return Empty.Array; } @@ -353,14 +334,9 @@ namespace IKVM.Reflection.Reader { return null; } - // TODO use binary search (if sorted) - int token = this.MetadataToken; - for (int i = 0; i < module.NestedClass.records.Length; i++) + foreach (int i in module.NestedClass.Filter(this.MetadataToken)) { - if (module.NestedClass.records[i].NestedClass == token) - { - return module.ResolveType(module.NestedClass.records[i].EnclosingClass, null, null); - } + return module.ResolveType(module.NestedClass.records[i].EnclosingClass, null, null); } throw new InvalidOperationException(); } @@ -411,16 +387,11 @@ namespace IKVM.Reflection.Reader public override bool __GetLayout(out int packingSize, out int typeSize) { - int token = this.MetadataToken; - // TODO use binary search? - for (int i = 0; i < module.ClassLayout.records.Length; i++) + foreach (int i in module.ClassLayout.Filter(this.MetadataToken)) { - if (module.ClassLayout.records[i].Parent == token) - { - packingSize = module.ClassLayout.records[i].PackingSize; - typeSize = module.ClassLayout.records[i].ClassSize; - return true; - } + packingSize = module.ClassLayout.records[i].PackingSize; + typeSize = module.ClassLayout.records[i].ClassSize; + return true; } packingSize = 0; typeSize = 0; @@ -439,12 +410,9 @@ namespace IKVM.Reflection.Reader internal override IList GetInterfaceImplCustomAttributes(Type interfaceType, Type attributeType) { - int token = this.MetadataToken; - // TODO use binary search? - for (int i = 0; i < module.InterfaceImpl.records.Length; i++) + foreach (int i in module.InterfaceImpl.Filter(this.MetadataToken)) { - if (module.InterfaceImpl.records[i].Class == token - && module.ResolveType(module.InterfaceImpl.records[i].Interface, this) == interfaceType) + if (module.ResolveType(module.InterfaceImpl.records[i].Interface, this) == interfaceType) { return module.GetCustomAttributes((InterfaceImplTable.Index << 24) | (i + 1), attributeType); }