diff options
| author | jpbruyere <jp.bruyere@hotmail.com> | 2017-01-01 11:24:34 +0100 |
|---|---|---|
| committer | jpbruyere <jp.bruyere@hotmail.com> | 2017-01-01 11:24:34 +0100 |
| commit | 6f5e0f0a2f4ea382626703c673f5df8d7c9a972b (patch) | |
| tree | 83ced24174db4cae60b7357fb805f8c021a91902 /src | |
| parent | e0a9da2413da9ba0a860baf064a39941178ee34a (diff) | |
replace Activator.CreateInstance in Instantiator with an Emited NewOjb
Diffstat (limited to 'src')
| -rw-r--r-- | src/CompilerServices/CompilerServices.cs | 2 | ||||
| -rw-r--r-- | src/IML/Context.cs | 19 | ||||
| -rw-r--r-- | src/Instantiator.cs | 11 |
3 files changed, 13 insertions, 19 deletions
diff --git a/src/CompilerServices/CompilerServices.cs b/src/CompilerServices/CompilerServices.cs index 0bd4b5c4..c0acc5d5 100644 --- a/src/CompilerServices/CompilerServices.cs +++ b/src/CompilerServices/CompilerServices.cs @@ -98,7 +98,7 @@ namespace Crow /// <param name="il">Il.</param> public static void emitSetCurInterface(ILGenerator il){ il.Emit (OpCodes.Ldloc_0); - il.Emit (OpCodes.Ldarg_2); + il.Emit (OpCodes.Ldarg_1); il.Emit (OpCodes.Stfld, miSetCurIface); } diff --git a/src/IML/Context.cs b/src/IML/Context.cs index 01cfa475..7f739c37 100644 --- a/src/IML/Context.cs +++ b/src/IML/Context.cs @@ -57,10 +57,15 @@ namespace Crow.IML { RootType = rootType; dm = new DynamicMethod ("dyn_instantiator", - typeof (void), new Type [] { typeof (Instantiator), typeof (object), typeof (Interface) }, true); + CompilerServices.TObject, new Type [] { typeof (Instantiator), typeof (Interface) }, true); il = dm.GetILGenerator (256); - initILGen (); + il.DeclareLocal (typeof (GraphicObject)); + il.Emit (OpCodes.Nop); + //set local GraphicObject to root object + il.Emit (OpCodes.Newobj, rootType.GetConstructors () [0]); + il.Emit (OpCodes.Stloc_0); + CompilerServices.emitSetCurInterface (il); } public NodeAddress CurrentNodeAddress { @@ -148,16 +153,6 @@ namespace Crow.IML bd.ResolveTargetName (resolvedNA); } - void initILGen () - { - il.DeclareLocal (typeof (GraphicObject)); - il.Emit (OpCodes.Nop); - //set local GraphicObject to root object passed as 1st argument - il.Emit (OpCodes.Ldarg_1); - il.Emit (OpCodes.Stloc_0); - CompilerServices.emitSetCurInterface (il); - } - /// <summary> /// Emits cached delegate handler addition in the context of instantiator (ctx) /// </summary> diff --git a/src/Instantiator.cs b/src/Instantiator.cs index e92e8995..402df1cc 100644 --- a/src/Instantiator.cs +++ b/src/Instantiator.cs @@ -32,7 +32,7 @@ using Crow.IML; namespace Crow { - public delegate void InstanciatorInvoker(object instance, Interface iface); + public delegate object InstanciatorInvoker(Interface iface); /// <summary> /// Instantiator @@ -87,10 +87,8 @@ namespace Crow } #endregion - public GraphicObject CreateInstance(Interface iface){ - GraphicObject tmp = (GraphicObject)Activator.CreateInstance(RootType); - loader (tmp, iface); - return tmp; + public GraphicObject CreateInstance(Interface iface){ + return loader (iface) as GraphicObject; } List<DynamicMethod> dsValueChangedDynMeths = new List<DynamicMethod>(); @@ -116,6 +114,7 @@ namespace Crow emitBindingDelegates (ctx); + ctx.il.Emit (OpCodes.Ldloc_0);//load root obj to return ctx.il.Emit(OpCodes.Ret); reader.Read ();//close tag @@ -209,7 +208,7 @@ namespace Crow if (string.IsNullOrEmpty (templatePath)) { ctx.il.Emit (OpCodes.Ldnull);//default template loading } else { - ctx.il.Emit (OpCodes.Ldarg_2);//load currentInterface + ctx.il.Emit (OpCodes.Ldarg_1);//load currentInterface ctx.il.Emit (OpCodes.Ldstr, templatePath); //Load template path string ctx.il.Emit (OpCodes.Callvirt,//call Interface.Load(path) CompilerServices.miIFaceLoad); |