Skip to content

Commit 02cf2f5

Browse files
committed
work-in-progress
1 parent 8376353 commit 02cf2f5

14 files changed

+186
-138
lines changed

Benchmark/Benchmark.cs

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -207,47 +207,47 @@ public override void RunOnce()
207207
}
208208

209209
#region Handwrittern //////////////////////////////////////////////////////////////////////
210-
public sealed class HandwrittenFooableEntwiner<T> : Entwiner, IFooable<T>
210+
public sealed class HandwrittenFooableEntwiner<T> : IFooable<T>
211211
{
212+
private readonly AnyCall any_call;
213+
212214
public HandwrittenFooableEntwiner( AnyCall any_call )
213-
: base( typeof(IFooable<T>), any_call )
214-
{ }
215+
{
216+
this.any_call = any_call;
217+
}
215218

216-
void IFooable<T>.Aardvark() => AnyCall( 0, Sys.Array.Empty<object>() );
217-
T IFooable<T>.Buffalo() => (T)AnyCall( 1, Sys.Array.Empty<object>() );
218-
void IFooable<T>.Crocodile( T t ) => AnyCall( 2, new object[] { t } );
219+
void IFooable<T>.Aardvark() => any_call( 0, Sys.Array.Empty<object>() );
220+
T IFooable<T>.Buffalo() => (T)any_call( 1, Sys.Array.Empty<object>() );
221+
void IFooable<T>.Crocodile( T t ) => any_call( 2, new object[] { t } );
219222

220223
void IFooable<T>.Dog( T t, out T ot )
221224
{
222225
var args = new object[] { t, default(T) };
223-
AnyCall( 3, args );
226+
any_call( 3, args );
224227
ot = (T)args[1];
225228
}
226229

227230
void IFooable<T>.Eagle( T t, ref T rt )
228231
{
229232
var args = new object[] { t, rt };
230-
AnyCall( 4, args );
233+
any_call( 4, args );
231234
rt = (T)args[1];
232235
}
233236

234-
T IFooable<T>.Flamingo { get => (T)AnyCall( 5, Sys.Array.Empty<object>() ); set => AnyCall( 6, new object[] { value } ); }
235-
T IFooable<T>.this[ T t ] { get => (T)AnyCall( 7, new object[] { t } ); set => AnyCall( 8, new object[] { t, value } ); }
237+
T IFooable<T>.Flamingo { get => (T)any_call( 5, Sys.Array.Empty<object>() ); set => any_call( 6, new object[] { value } ); }
238+
T IFooable<T>.this[ T t ] { get => (T)any_call( 7, new object[] { t } ); set => any_call( 8, new object[] { t, value } ); }
236239
}
237240

238-
private sealed class HandwrittenFooableUntwiner<T> : Untwiner
241+
private sealed class HandwrittenFooableUntwiner<T>
239242
{
240243
private readonly IFooable<T> target;
241244

242245
public HandwrittenFooableUntwiner( IFooable<T> target )
243-
: base( typeof(IFooable<T>) )
244246
{
245247
this.target = target;
246248
}
247249

248-
public override object Target => target;
249-
250-
public override object AnyCall( int selector, object[] args )
250+
public object AnyCall( int selector, object[] args )
251251
{
252252
switch( selector )
253253
{
@@ -295,8 +295,8 @@ private sealed class BenchmarkHandwrittenInvocation : Benchmark
295295
public BenchmarkHandwrittenInvocation()
296296
{
297297
IFooable<string> fooable = new FooImplementation<string>();
298-
Untwiner untwiner = new HandwrittenFooableUntwiner<string>( fooable );
299-
entwiner = new HandwrittenFooableEntwiner<string>( untwiner.AnyCall );
298+
AnyCall untwiner = new HandwrittenFooableUntwiner<string>( fooable ).AnyCall;
299+
entwiner = new HandwrittenFooableEntwiner<string>( untwiner );
300300
}
301301

302302
public override void RunOnce()
@@ -307,20 +307,20 @@ public override void RunOnce()
307307
#endregion
308308

309309
#region Castle Benchmarking Routines //////////////////////////////////////////////////////
310-
private sealed class BenchmarkCastleCreation/*WithCaching*/ : Benchmark
310+
private sealed class BenchmarkCastleCreation /*WithCaching*/ : Benchmark
311311
{
312312
private readonly IFooable<string> fooable;
313313

314-
public BenchmarkCastleCreation/*WithCaching*/()
314+
public BenchmarkCastleCreation /*WithCaching*/()
315315
{
316316
fooable = new FooImplementation<string>();
317317
//CastleProxyGenerator.ProxyBuilder.ModuleScope.IsCaching = true; This used to compile, but not anymore. It appears that they discontinued the "IsCaching" property.
318318
}
319319

320320
public override void RunOnce()
321321
{
322-
Untwiner untwiner = CastleGetUntwiner( fooable );
323-
CastleGetEntwiner<IFooable<string>>( untwiner.AnyCall );
322+
AnyCall untwiner = CastleGetUntwiner( fooable );
323+
CastleGetEntwiner<IFooable<string>>( untwiner );
324324
}
325325
}
326326

@@ -331,8 +331,8 @@ private sealed class BenchmarkCastleInvocation : Benchmark
331331
public BenchmarkCastleInvocation()
332332
{
333333
IFooable<string> fooable = new FooImplementation<string>();
334-
Untwiner untwiner = CastleGetUntwiner( fooable );
335-
entwiner = CastleGetEntwiner<IFooable<string>>( untwiner.AnyCall );
334+
AnyCall untwiner = CastleGetUntwiner( fooable );
335+
entwiner = CastleGetEntwiner<IFooable<string>>( untwiner );
336336
}
337337

338338
public override void RunOnce()
@@ -349,28 +349,29 @@ public static T CastleGetEntwiner<T>( AnyCall any_call ) where T : class //actua
349349
return CastleProxyGenerator.CreateInterfaceProxyWithoutTarget<T>( interceptor );
350350
}
351351

352-
public static Untwiner CastleGetUntwiner<T>( T target ) where T : class //actually, interface
352+
public static AnyCall CastleGetUntwiner<T>( T target ) where T : class //actually, interface
353353
{
354354
// The Castle DynamicProxy does not offer any untwining functionality, so we use a reflecting untwiner.
355-
return new ReflectingUntwiner( typeof(T), target );
355+
return new ReflectingUntwiner( typeof(T), target ).AnyCall;
356356
}
357357

358-
private sealed class EntwinerForCastle : Entwiner, CastleDP.IInterceptor
358+
private sealed class EntwinerForCastle : CastleDP.IInterceptor
359359
{
360+
private readonly AnyCall any_call;
360361
private readonly Dictionary<SysReflect.MethodInfo, int> selector_map = new Dictionary<SysReflect.MethodInfo, int>();
361362

362363
public EntwinerForCastle( System.Type interface_type, AnyCall any_call )
363-
: base( interface_type, any_call )
364364
{
365-
var method_infos = InterfaceType.GetMethods( SysReflect.BindingFlags.Public | SysReflect.BindingFlags.NonPublic | SysReflect.BindingFlags.Instance );
365+
this.any_call = any_call;
366+
var method_infos = interface_type.GetMethods( SysReflect.BindingFlags.Public | SysReflect.BindingFlags.NonPublic | SysReflect.BindingFlags.Instance );
366367
for( int i = 0; i < method_infos.Length; i++ )
367368
selector_map.Add( method_infos[i], i );
368369
}
369370

370371
void CastleDP.IInterceptor.Intercept( CastleDP.IInvocation invocation )
371372
{
372373
int selector = selector_map[invocation.Method];
373-
invocation.ReturnValue = AnyCall( selector, invocation.Arguments );
374+
invocation.ReturnValue = any_call( selector, invocation.Arguments );
374375
}
375376
}
376377
#endregion
@@ -475,22 +476,23 @@ public static AnyCall LinFuGetUntwiner<T>( T target )
475476
return new ReflectingUntwiner( typeof(T), target ).AnyCall;
476477
}
477478

478-
private sealed class EntwinerForLinFu : Entwiner, LinFuDP.IInterceptor
479+
private sealed class EntwinerForLinFu : LinFuDP.IInterceptor
479480
{
481+
private readonly AnyCall any_call;
480482
private readonly Dictionary<SysReflect.MethodInfo, int> selector_map = new Dictionary<SysReflect.MethodInfo, int>();
481483

482-
public EntwinerForLinFu( System.Type interface_type, AnyCall any_call )
483-
: base( interface_type, any_call )
484+
public EntwinerForLinFu( Sys.Type interface_type, AnyCall any_call )
484485
{
485-
var method_infos = InterfaceType.GetMethods( SysReflect.BindingFlags.Public | SysReflect.BindingFlags.NonPublic | SysReflect.BindingFlags.Instance );
486+
this.any_call = any_call;
487+
var method_infos = interface_type.GetMethods( SysReflect.BindingFlags.Public | SysReflect.BindingFlags.NonPublic | SysReflect.BindingFlags.Instance );
486488
for( int i = 0; i < method_infos.Length; i++ )
487489
selector_map.Add( method_infos[i], i );
488490
}
489491

490492
object LinFuDP.IInterceptor.Intercept( LinFuDP.InvocationInfo info )
491493
{
492494
int selector = selector_map[info.TargetMethod];
493-
return AnyCall( selector, info.Arguments );
495+
return any_call( selector, info.Arguments );
494496
}
495497
}
496498
#endregion

Benchmark/ReflectingUntwiner.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@
22

33
namespace MikeNakis.Intertwine.Benchmark
44
{
5+
using Sys = System;
6+
57
/// <summary>
68
/// An untwiner which uses reflection to do its job. Keep for reference. WARNING: SLOW AS MOLASSES.
79
/// </summary>
8-
public class ReflectingUntwiner : Untwiner
10+
public class ReflectingUntwiner
911
{
10-
private readonly System.Reflection.MethodInfo[] method_infos;
12+
private readonly object target;
13+
private readonly Sys.Reflection.MethodInfo[] method_infos;
1114

12-
public ReflectingUntwiner( System.Type interface_type, object target )
13-
: base( interface_type )
15+
public ReflectingUntwiner( Sys.Type interface_type, object target )
1416
{
15-
Target = target;
16-
method_infos = InterfaceType.GetMethods( System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance );
17+
this.target = target;
18+
method_infos = interface_type.GetMethods( System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance );
1719
}
1820

19-
public override object Target { get; }
20-
21-
public override object AnyCall( int selector, object[] arguments )
21+
public object AnyCall( int selector, object[] arguments )
2222
{
23-
return method_infos[selector].Invoke( Target, arguments );
23+
return method_infos[selector].Invoke( target, arguments );
2424
}
2525
}
2626
}

InterfaceEvents/InterfaceEventManager.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ namespace MikeNakis.Intertwine.InterfaceEvents
1414
[SysDiag.DebuggerDisplay( "{" + nameof(DebugView) + ",nq}" )]
1515
public sealed class InterfaceEventManager<I> : IInterfaceEventSource<I> where I : class
1616
{
17-
[SysDiag.DebuggerBrowsable( SysDiag.DebuggerBrowsableState.RootHidden )] public Untwiner[] DebugView => untwiners.ToArray();
17+
[SysDiag.DebuggerBrowsable( SysDiag.DebuggerBrowsableState.RootHidden )] public AnyCall[] DebugView => untwiners.ToArray();
1818
private readonly IntertwineFactory intertwine_factory;
19-
private readonly List<Untwiner> untwiners = new List<Untwiner>();
19+
private readonly List<AnyCall> untwiners = new List<AnyCall>();
2020

2121
/// <summary>
2222
/// The trigger of the event. (Invoke this to cause the event to be triggered.)
@@ -51,7 +51,7 @@ void IInterfaceEventSource<I>.RegisterObserver( bool register, I observer )
5151
{
5252
if( register )
5353
{
54-
Untwiner untwiner = intertwine_factory.GetIntertwine<I>().NewUntwiner( observer );
54+
AnyCall untwiner = intertwine_factory.GetIntertwine<I>().NewUntwiningInstance( observer );
5555
Dbg.Assert( !Source.IsObserverRegistered( observer ) ); //observer is already registered.
5656
untwiners.Add( untwiner );
5757
}
@@ -69,7 +69,7 @@ bool IInterfaceEventSource<I>.IsObserverRegistered( I observer )
6969
return find_untwiner_by_observer( observer ) != null;
7070
}
7171

72-
private Untwiner find_untwiner_by_observer( I observer )
72+
private AnyCall find_untwiner_by_observer( I observer )
7373
{
7474
foreach( var untwiner in untwiners )
7575
if( untwiner.Target == observer )
@@ -84,7 +84,7 @@ private object any_call( int selector, object[] args )
8484
int hashcode = get_hashcode( args );
8585
foreach( var untwiner in untwiners.ToArray() )
8686
{
87-
untwiner.AnyCall( selector, args );
87+
untwiner.Invoke( selector, args );
8888
Dbg.Assert( get_hashcode( args ) == hashcode ); // Ensure that the untwiner did not alter any arguments.
8989
}
9090
if( Dbg.False )
@@ -96,7 +96,7 @@ private object any_call( int selector, object[] args )
9696
{
9797
try
9898
{
99-
untwiner.AnyCall( selector, args );
99+
untwiner.Invoke( selector, args );
100100
}
101101
catch( System.Exception e )
102102
{

Intertwine.sln

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ VisualStudioVersion = 12.0.31101.0
44
MinimumVisualStudioVersion = 10.0.40219.1
55
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{FA184FB0-3834-44F4-A391-0AE48034E0D0}"
66
EndProject
7-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Intertwine", "Intertwine\Intertwine.csproj", "{B840485B-A5C6-4D9B-A8FF-67E971B2C488}"
7+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Intertwine", "Intertwine\MikeNakis.Intertwine.csproj", "{B840485B-A5C6-4D9B-A8FF-67E971B2C488}"
88
EndProject
9-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test", "Test\Test.csproj", "{C2E57D84-8AF9-4992-87B2-5D8897A91481}"
9+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test", "Test\MikeNakis.Intertwine Test.csproj", "{C2E57D84-8AF9-4992-87B2-5D8897A91481}"
1010
ProjectSection(ProjectDependencies) = postProject
1111
{B840485B-A5C6-4D9B-A8FF-67E971B2C488} = {B840485B-A5C6-4D9B-A8FF-67E971B2C488}
1212
EndProjectSection
1313
EndProject
14-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InterfaceEvents", "InterfaceEvents\InterfaceEvents.csproj", "{1816F332-8FC7-4E95-A8D3-2D53B33D4F9C}"
14+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InterfaceEvents", "InterfaceEvents\MikeNakis.Intertwine.InterfaceEvents.csproj", "{1816F332-8FC7-4E95-A8D3-2D53B33D4F9C}"
1515
EndProject
16-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Benchmark", "Benchmark\Benchmark.csproj", "{DA9C27C3-6348-4D2A-A8B0-AF69CD49FE18}"
16+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Benchmark", "Benchmark\MikeNakis.Intertwine.Benchmark.csproj", "{DA9C27C3-6348-4D2A-A8B0-AF69CD49FE18}"
1717
EndProject
1818
Global
1919
GlobalSection(SolutionConfigurationPlatforms) = preSolution

Intertwine.sln.DotSettings

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
11
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2-
<s:Boolean x:Key="/Default/UserDictionary/Words/=Entwiner/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
2+
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=Locals/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aa_bb" /&gt;</s:String>
3+
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=Parameters/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aa_bb" /&gt;</s:String>
4+
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aa_bb" /&gt;</s:String>
5+
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=59618f95_002Dfd13_002D44b2_002D86ba_002Dd82abdd718a5/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Static, Instance" AccessRightKinds="Private" Description="Method (private)"&gt;&lt;ElementKinds&gt;&lt;Kind Name="ASYNC_METHOD" /&gt;&lt;Kind Name="METHOD" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aa_bb" /&gt;&lt;/Policy&gt;</s:String>
6+
<s:Boolean x:Key="/Default/UserDictionary/Words/=Entwiner/@EntryIndexedValue">True</s:Boolean>
7+
<s:Boolean x:Key="/Default/UserDictionary/Words/=entwiners/@EntryIndexedValue">True</s:Boolean>
8+
<s:Boolean x:Key="/Default/UserDictionary/Words/=Nakis/@EntryIndexedValue">True</s:Boolean>
9+
<s:Boolean x:Key="/Default/UserDictionary/Words/=untwined/@EntryIndexedValue">True</s:Boolean>
10+
<s:Boolean x:Key="/Default/UserDictionary/Words/=Untwiner/@EntryIndexedValue">True</s:Boolean>
11+
<s:Boolean x:Key="/Default/UserDictionary/Words/=untwiners/@EntryIndexedValue">True</s:Boolean>
12+
<s:Boolean x:Key="/Default/UserDictionary/Words/=Untwining/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

Intertwine/AnyCall.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ namespace MikeNakis.Intertwine
77
/// <param name="selector">The ordinal number of the interface method being called.</param>
88
/// <param name="arguments">An array of objects containing the arguments of the call.</param>
99
/// <returns>An object representing the return value of the method call.</returns>
10+
///<author>michael.gr</author>
1011
public delegate object AnyCall( int selector, object[] arguments );
1112
}

Intertwine/CachingIntertwine.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ namespace MikeNakis.Intertwine
66
using System.Collections.Generic;
77
using Sys = System;
88

9-
/// <summary> A decorator of <see cref="IntertwineFactory" /> which adds caching.</summary>
9+
///<summary>A decorator of <see cref="IntertwineFactory" /> which adds caching.</summary>
10+
///<author>michael.gr</author>
1011
public class CachingIntertwineFactory : IntertwineFactory
1112
{
1213
private readonly IntertwineFactory decoree;

0 commit comments

Comments
 (0)