Update of /cvsroot/iiop-net/IIOPNet/IIOPChannel
In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv14959/IIOPChannel
Modified Files:
AttributeExtCollection.cs Serializer.cs SerializerFactory.cs
Log Message:
IdlSequenceSerializer now generic for .NET > 2.0 -> this brings 20% performance in the benchmark
use /define:NET_2 while compiling IIOPChannel to activate this improvement.
Index: Serializer.cs
===================================================================
RCS file: /cvsroot/iiop-net/IIOPNet/IIOPChannel/Serializer.cs,v
retrieving revision 1.62
retrieving revision 1.63
diff -C2 -d -r1.62 -r1.63
*** Serializer.cs 10 Sep 2006 11:06:54 -0000 1.62
--- Serializer.cs 26 Nov 2006 17:06:46 -0000 1.63
***************
*** 1391,1395 ****
--- 1391,1399 ----
/// <summary>serializes idl sequences</summary>
+ #if NET_2
+ internal class IdlSequenceSerializer<T> : Serializer {
+ #else
internal class IdlSequenceSerializer : Serializer {
+ #endif
#region IFields
***************
*** 1406,1410 ****
--- 1410,1416 ----
/// default constructor.
/// </summary>
+ #if !NET_2
/// <param name="forType">The sequence type</param>
+ #endif
/// <param name="elemAttrs">The sequence element type attributes</param>
/// <param name="bound">the number of elements allowed maximally</param>
***************
*** 1412,1419 ****
/// as empty sequence.</param>
/// <param name="serFactory">The serializer factory created this serializer</param>
! public IdlSequenceSerializer(Type forType, AttributeExtCollection elemAttrs,
int bound, bool allowNull, SerializerFactory serFactory) {
m_allowNull = allowNull;
m_forTypeElemType = forType.GetElementType();
m_bound = bound;
// element is not the same than the sequence -> therefore problems with recursion
--- 1418,1433 ----
/// as empty sequence.</param>
/// <param name="serFactory">The serializer factory created this serializer</param>
! public IdlSequenceSerializer(
! #if !NET_2
! Type forType,
! #endif
! AttributeExtCollection elemAttrs,
int bound, bool allowNull, SerializerFactory serFactory) {
m_allowNull = allowNull;
+ #if NET_2
+ m_forTypeElemType = typeof(T);
+ #else
m_forTypeElemType = forType.GetElementType();
+ #endif
m_bound = bound;
// element is not the same than the sequence -> therefore problems with recursion
***************
*** 1446,1450 ****
--- 1460,1468 ----
return;
}
+ #if NET_2
+ T[] array = (T[]) actual;
+ #else
Array array = (Array) actual;
+ #endif
// not allowed for a sequence:
CheckActualNotNull(array);
***************
*** 1454,1458 ****
for (int i = 0; i < array.Length; i++) {
// it's more efficient to not determine serialise for each element; instead use cached ser
! m_elementSerializer.Serialize(array.GetValue(i), targetStream);
}
}
--- 1472,1482 ----
for (int i = 0; i < array.Length; i++) {
// it's more efficient to not determine serialise for each element; instead use cached ser
! m_elementSerializer.Serialize(
! #if NET_2
! array[i],
! #else
! array.GetValue(i),
! #endif
! targetStream);
}
}
***************
*** 1462,1472 ****
uint nrOfElements = sourceStream.ReadULong();
CheckBound(nrOfElements);
!
Array result = Array.CreateInstance(m_forTypeElemType, (int)nrOfElements);
// serialize sequence elements
for (int i = 0; i < nrOfElements; i++) {
// it's more efficient to not determine serialise for each element; instead use cached ser
object entry = m_elementSerializer.Deserialize(sourceStream);
result.SetValue(entry, i);
}
return result;
--- 1486,1504 ----
uint nrOfElements = sourceStream.ReadULong();
CheckBound(nrOfElements);
!
! #if NET_2
! T[] result = new T[nrOfElements];
! #else
Array result = Array.CreateInstance(m_forTypeElemType, (int)nrOfElements);
+ #endif
// serialize sequence elements
for (int i = 0; i < nrOfElements; i++) {
// it's more efficient to not determine serialise for each element; instead use cached ser
object entry = m_elementSerializer.Deserialize(sourceStream);
+ #if NET_2
+ result[i] = (T) entry;
+ #else
result.SetValue(entry, i);
+ #endif
}
return result;
***************
*** 3175,3180 ****
--- 3207,3217 ----
Assertion.AssertNotNull("ser", ser);
+ #if NET_2
+ Assertion.AssertEquals("ser type", typeof(IdlSequenceSerializer<>).MakeGenericType(m_seqType.GetElementType()),
+ ser.GetType());
+ #else
Assertion.AssertEquals("ser type", typeof(IdlSequenceSerializer),
ser.GetType());
+ #endif
GenericSerTest(ser, actual, expected);
Index: SerializerFactory.cs
===================================================================
RCS file: /cvsroot/iiop-net/IIOPNet/IIOPChannel/SerializerFactory.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** SerializerFactory.cs 22 Aug 2006 22:34:25 -0000 1.2
--- SerializerFactory.cs 26 Nov 2006 17:06:46 -0000 1.3
***************
*** 30,33 ****
--- 30,34 ----
using System;
using System.Collections;
+ using System.Reflection;
using System.Diagnostics;
using Ch.Elca.Iiop.Util;
***************
*** 49,52 ****
--- 50,55 ----
private static ClsToIdlMapper s_mapper = ClsToIdlMapper.GetSingleton();
+ private static readonly Type ClassType = typeof(SerializerFactory);
+
#endregion SFields
#region IFields
***************
*** 265,271 ****
public object MapToIdlSequence(System.Type clsType, int bound, AttributeExtCollection allAttributes, AttributeExtCollection elemTypeAttributes) {
! return new IdlSequenceSerializer(clsType, elemTypeAttributes, bound,
m_config.SequenceSerializationAllowNull,
this);
}
public object MapToIdlArray(System.Type clsType, int[] dimensions, AttributeExtCollection allAttributes, AttributeExtCollection elemTypeAttributes) {
--- 268,282 ----
public object MapToIdlSequence(System.Type clsType, int bound, AttributeExtCollection allAttributes, AttributeExtCollection elemTypeAttributes) {
! #if NET_2
! Type serializerType = typeof(IdlSequenceSerializer<>).MakeGenericType(clsType.GetElementType());
! ConstructorInfo ci = serializerType.GetConstructor(new Type[] {
! AttributeExtCollection.ClassType, ReflectionHelper.Int32Type, ReflectionHelper.BooleanType,
! SerializerFactory.ClassType });
! return ci.Invoke(new object[] { elemTypeAttributes, bound, m_config.SequenceSerializationAllowNull, this });
! #else
! return new IdlSequenceSerializer(clsType, elemTypeAttributes, bound,
m_config.SequenceSerializationAllowNull,
this);
+ #endif
}
public object MapToIdlArray(System.Type clsType, int[] dimensions, AttributeExtCollection allAttributes, AttributeExtCollection elemTypeAttributes) {
Index: AttributeExtCollection.cs
===================================================================
RCS file: /cvsroot/iiop-net/IIOPNet/IIOPChannel/AttributeExtCollection.cs,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** AttributeExtCollection.cs 22 Aug 2006 22:34:22 -0000 1.14
--- AttributeExtCollection.cs 26 Nov 2006 17:06:46 -0000 1.15
***************
*** 44,48 ****
#region SFields
! private static AttributeExtCollection s_emptyCollection = new AttributeExtCollection();
#endregion
--- 44,50 ----
#region SFields
! private static AttributeExtCollection s_emptyCollection = new AttributeExtCollection();
!
! public static readonly Type ClassType = typeof(AttributeExtCollection);
#endregion
|