Author: ankit
Date: 2005-04-27 04:48:14 -0400 (Wed, 27 Apr 2005)
New Revision: 43644
Modified:
trunk/mcs/ilasm/codegen/ChangeLog
trunk/mcs/ilasm/codegen/ExternTypeRefInst.cs
trunk/mcs/ilasm/codegen/PeapiTypeRef.cs
trunk/mcs/ilasm/codegen/PrimitiveTypeRef.cs
Log:
* ExternTypeRefInst.cs (ExternTypeRefInst.GetMethodRef): Use method_table to
avoid
creating duplicates.
* PrimitiveTypeRef.cs (PrimitiveTypeRef.GetMethodRef): Use method_table to
avoid
creating duplicates
* PeapiTypeRef.cs (Pair): New class. Tuple of PEAPI.Type and string.
(PeapiTypeRef.type_table): New.
(PeapiTypeRef.MakeArray, MakeBoundArray, MakeManagedPointer,
MakeUnmanagedPointer,
MakeCustomModified): Use type_table to avoid creating duplicates.
Modified: trunk/mcs/ilasm/codegen/ChangeLog
===================================================================
--- trunk/mcs/ilasm/codegen/ChangeLog 2005-04-27 07:39:34 UTC (rev 43643)
+++ trunk/mcs/ilasm/codegen/ChangeLog 2005-04-27 08:48:14 UTC (rev 43644)
@@ -1,3 +1,14 @@
+2005-04-27 Ankit Jain <[EMAIL PROTECTED]>
+
+ * ExternTypeRefInst.cs (ExternTypeRefInst.GetMethodRef): Use
method_table to avoid
+ creating duplicates.
+ * PrimitiveTypeRef.cs (PrimitiveTypeRef.GetMethodRef): Use method_table
to avoid
+ creating duplicates
+ * PeapiTypeRef.cs (Pair): New class. Tuple of PEAPI.Type and string.
+ (PeapiTypeRef.type_table): New.
+ (PeapiTypeRef.MakeArray, MakeBoundArray, MakeManagedPointer,
MakeUnmanagedPointer,
+ MakeCustomModified): Use type_table to avoid creating duplicates.
+
2005-04-22 Atsushi Enomoto <[EMAIL PROTECTED]>
* InstrTable.cs :
Modified: trunk/mcs/ilasm/codegen/ExternTypeRefInst.cs
===================================================================
--- trunk/mcs/ilasm/codegen/ExternTypeRefInst.cs 2005-04-27 07:39:34 UTC
(rev 43643)
+++ trunk/mcs/ilasm/codegen/ExternTypeRefInst.cs 2005-04-27 08:48:14 UTC
(rev 43644)
@@ -19,6 +19,7 @@
private PEAPI.Type type;
private bool is_valuetypeinst;
private bool is_resolved;
+ private static Hashtable method_table = new Hashtable ();
public ExternTypeRefInst (ExternTypeRef type_ref, bool
is_valuetypeinst)
{
@@ -116,7 +117,14 @@
public IMethodRef GetMethodRef (ITypeRef ret_type,
PEAPI.CallConv call_conv,
string name, ITypeRef[] param)
{
- return new TypeSpecMethodRef (this, ret_type,
call_conv, name, param);
+ string key = type_ref.FullName +
MethodDef.CreateSignature (ret_type, name, param) + type_ref.SigMod;
+ TypeSpecMethodRef mr = method_table [key] as
TypeSpecMethodRef;
+ if (mr == null) {
+ mr = new TypeSpecMethodRef (this, ret_type,
call_conv, name, param);
+ method_table [key] = mr;
+ }
+
+ return mr;
}
public IFieldRef GetFieldRef (ITypeRef ret_type, string name)
Modified: trunk/mcs/ilasm/codegen/PeapiTypeRef.cs
===================================================================
--- trunk/mcs/ilasm/codegen/PeapiTypeRef.cs 2005-04-27 07:39:34 UTC (rev
43643)
+++ trunk/mcs/ilasm/codegen/PeapiTypeRef.cs 2005-04-27 08:48:14 UTC (rev
43644)
@@ -12,7 +12,32 @@
using System.Collections;
namespace Mono.ILASM {
+ public class Pair {
+ private PEAPI.Type type;
+ private string sig;
+ public Pair (PEAPI.Type type, string sig)
+ {
+ this.type = type;
+ this.sig = sig;
+ }
+
+ public override int GetHashCode ()
+ {
+ return type.GetHashCode () ^ sig.GetHashCode ();
+ }
+
+ public override bool Equals (Object o)
+ {
+ Pair p = o as Pair;
+
+ if (p == null)
+ return false;
+
+ return (p.type == this.type && p.sig == this.sig);
+ }
+ }
+
public class PeapiTypeRef {
private PEAPI.Type peapi_type;
@@ -21,6 +46,8 @@
private bool is_ref;
private bool use_type_spec;
+ private static Hashtable type_table = new Hashtable ();
+
public PeapiTypeRef (PEAPI.Type peapi_type)
{
this.peapi_type = peapi_type;
@@ -52,14 +79,24 @@
public void MakeArray ()
{
+ PEAPI.Type type;
+
use_type_spec = true;
- peapi_type = new PEAPI.ZeroBasedArray (peapi_type);
is_array = true;
+
+ Pair p = new Pair (peapi_type, "[]");
+ type = type_table [p] as PEAPI.Type;
+ if (type == null) {
+ type = new PEAPI.ZeroBasedArray (peapi_type);
+ type_table [p] = type;
+ }
+ peapi_type = type;
}
public void MakeBoundArray (ArrayList bound_list)
{
use_type_spec = true;
+ is_array = true;
int dimen = bound_list.Count;
int[] lower_array = new int[dimen];
@@ -68,7 +105,30 @@
bool size_set = false;
bool prev_lower_set = true;
bool prev_size_set = true;
+ string sigmod = "";
+ PEAPI.Type type;
+ Pair p;
+ sigmod += "[";
+ for (int i=0; i<bound_list.Count; i++) {
+ DictionaryEntry e = (DictionaryEntry)
bound_list [i];
+ if (e.Key != TypeRef.Ellipsis)
+ sigmod += e.Key;
+ sigmod += "...";
+ if (e.Value != TypeRef.Ellipsis)
+ sigmod += e.Value;
+ if (i + 1 < bound_list.Count)
+ sigmod += ", ";
+ }
+ sigmod += "]";
+
+ p = new Pair (peapi_type, sigmod);
+ type = type_table [p] as PEAPI.Type;
+ if (type != null) {
+ peapi_type = type;
+ return;
+ }
+
// TODO: There should probably be an error reported if
// something like [3...,3...5] is done
for (int i=0; i<dimen; i++) {
@@ -98,32 +158,55 @@
} else {
peapi_type = new PEAPI.BoundArray (peapi_type,
(uint) dimen);
}
- is_array = true;
+
+ type_table [p] = peapi_type;
}
public void MakeManagedPointer ()
{
+ PEAPI.Type type;
use_type_spec = true;
+ is_ref = true;
- peapi_type = new PEAPI.ManagedPointer (peapi_type);
- is_ref = true;
+ Pair p = new Pair (peapi_type, "&");
+ type = type_table [p] as PEAPI.Type;
+ if (type == null) {
+ type = new PEAPI.ManagedPointer (peapi_type);
+ type_table [p] = type;
+ }
+ peapi_type = type;
}
public void MakeUnmanagedPointer ()
{
+ PEAPI.Type type;
use_type_spec = true;
- peapi_type = new PEAPI.UnmanagedPointer (peapi_type);
+ Pair p = new Pair (peapi_type, "*");
+ type = type_table [p] as PEAPI.Type;
+ if (type == null) {
+ type = new PEAPI.UnmanagedPointer (peapi_type);
+ type_table [p] = type;
+ }
+ peapi_type = type;
}
public void MakeCustomModified (CodeGen code_gen,
PEAPI.CustomModifier modifier,
IClassRef klass)
{
+ PEAPI.Type type;
+
use_type_spec = true;
-
- klass.Resolve (code_gen);
- peapi_type = new PEAPI.CustomModifiedType (peapi_type,
+
+ Pair p = new Pair (peapi_type, modifier.ToString ());
+ type = type_table [p] as PEAPI.Type;
+ if (type == null) {
+ klass.Resolve (code_gen);
+ type = new PEAPI.CustomModifiedType
(peapi_type,
modifier, klass.PeapiClass);
+ type_table [p] = type;
+ }
+ peapi_type = type;
}
public void MakePinned ()
Modified: trunk/mcs/ilasm/codegen/PrimitiveTypeRef.cs
===================================================================
--- trunk/mcs/ilasm/codegen/PrimitiveTypeRef.cs 2005-04-27 07:39:34 UTC (rev
43643)
+++ trunk/mcs/ilasm/codegen/PrimitiveTypeRef.cs 2005-04-27 08:48:14 UTC (rev
43644)
@@ -9,6 +9,7 @@
using System;
+using System.Collections;
namespace Mono.ILASM {
@@ -22,6 +23,7 @@
private PEAPI.Type type;
private bool is_resolved;
+ private static Hashtable method_table = new Hashtable ();
public PrimitiveTypeRef (PEAPI.PrimitiveType type, string
full_name)
{
@@ -76,7 +78,14 @@
public IMethodRef GetMethodRef (ITypeRef ret_type,
PEAPI.CallConv call_conv,
string name, ITypeRef[] param)
{
- return new TypeSpecMethodRef (this, ret_type,
call_conv, name, param);
+ string key = full_name + MethodDef.CreateSignature
(ret_type, name, param) + sig_mod;
+ TypeSpecMethodRef mr = method_table [key] as
TypeSpecMethodRef;
+ if (mr != null)
+ return mr;
+
+ mr = new TypeSpecMethodRef (this, ret_type, call_conv,
name, param);
+ method_table [key] = mr;
+ return mr;
}
public IFieldRef GetFieldRef (ITypeRef ret_type, string name)
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches