From: <fab...@us...> - 2009-02-07 05:00:02
|
Revision: 4065 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4065&view=rev Author: fabiomaulo Date: 2009-02-07 04:59:58 +0000 (Sat, 07 Feb 2009) Log Message: ----------- Fix NH-1660 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/NHibernate.csproj trunk/nhibernate/src/NHibernate/Tuple/EntityModeToTuplizerMapping.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate/EntityModeEqualityComparer.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/EntityModeToTuplizerPerf/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/EntityModeToTuplizerPerf/Fixture.cs Added: trunk/nhibernate/src/NHibernate/EntityModeEqualityComparer.cs =================================================================== --- trunk/nhibernate/src/NHibernate/EntityModeEqualityComparer.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/EntityModeEqualityComparer.cs 2009-02-07 04:59:58 UTC (rev 4065) @@ -0,0 +1,17 @@ +using System.Collections.Generic; + +namespace NHibernate +{ + public class EntityModeEqualityComparer : IEqualityComparer<EntityMode> + { + public bool Equals(EntityMode x, EntityMode y) + { + return x == y; + } + + public int GetHashCode(EntityMode obj) + { + return (int) obj; + } + } +} \ No newline at end of file Property changes on: trunk/nhibernate/src/NHibernate/EntityModeEqualityComparer.cs ___________________________________________________________________ Added: svn:mergeinfo + Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj =================================================================== --- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-02-07 04:34:49 UTC (rev 4064) +++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-02-07 04:59:58 UTC (rev 4065) @@ -460,6 +460,7 @@ <Compile Include="Dialect\SybaseASA9Dialect.cs" /> <Compile Include="Driver\IfxDriver.cs" /> <Compile Include="Driver\OracleLiteDataClientDriver.cs" /> + <Compile Include="EntityModeEqualityComparer.cs" /> <Compile Include="Event\IDestructible.cs" /> <Compile Include="Exceptions\ReflectionBasedSqlStateExtracter.cs" /> <Compile Include="Exceptions\SqlStateExtracter.cs" /> Modified: trunk/nhibernate/src/NHibernate/Tuple/EntityModeToTuplizerMapping.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Tuple/EntityModeToTuplizerMapping.cs 2009-02-07 04:34:49 UTC (rev 4064) +++ trunk/nhibernate/src/NHibernate/Tuple/EntityModeToTuplizerMapping.cs 2009-02-07 04:59:58 UTC (rev 4065) @@ -8,8 +8,9 @@ [Serializable] public abstract class EntityModeToTuplizerMapping { - // map of EntityMode -> Tuplizer - private readonly IDictionary<EntityMode, ITuplizer> tuplizers = new LinkedHashMap<EntityMode, ITuplizer>(); + // NH-1660 + private readonly IDictionary<EntityMode, ITuplizer> tuplizers + = new LinkedHashMap<EntityMode, ITuplizer>(5, new EntityModeEqualityComparer()); protected internal void AddTuplizer(EntityMode entityMode, ITuplizer tuplizer) { Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/EntityModeToTuplizerPerf/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/EntityModeToTuplizerPerf/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/EntityModeToTuplizerPerf/Fixture.cs 2009-02-07 04:59:58 UTC (rev 4065) @@ -0,0 +1,93 @@ +using System; +using System.Diagnostics; +using NHibernate.Tuple; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.EntityModeToTuplizerPerf +{ + [TestFixture] + public class Fixture + { + private TargetClazz target; + + [SetUp] + public void Setup() + { + target = new TargetClazz(); + } + + [Test] + public void VerifyEntityModeNotFound() + { + Assert.IsNull(target.GetTuplizerOrNull(EntityMode.Xml)); + } + + [Test] + public void VerifyEntityModeFound() + { + ITuplizer tuplizer = new TuplizerStub(); + target.Add(EntityMode.Map, tuplizer); + Assert.AreSame(tuplizer, target.GetTuplizerOrNull(EntityMode.Map)); + } + + [Test, Explicit("To the commiter - run before and after")] + public void RemoveThisTest_JustToShowPerfDifference() + { + const int loop = 1000000; + target.Add(EntityMode.Map, new TuplizerStub()); + target.Add(EntityMode.Poco, new TuplizerStub()); + target.Add(EntityMode.Xml, new TuplizerStub()); + + var watch = new Stopwatch(); + watch.Start(); + for (int i = 0; i < loop; i++) + { + target.GetTuplizerOrNull(EntityMode.Map); + target.GetTuplizerOrNull(EntityMode.Poco); + } + watch.Stop(); + Console.WriteLine(watch.ElapsedMilliseconds); + } + + private class TargetClazz : EntityModeToTuplizerMapping + { + public void Add(EntityMode eMode, ITuplizer tuplizer) + { + AddTuplizer(eMode, tuplizer); + } + } + + private class TuplizerStub : ITuplizer + { + public System.Type MappedClass + { + get { throw new NotImplementedException(); } + } + + public object[] GetPropertyValues(object entity) + { + throw new NotImplementedException(); + } + + public void SetPropertyValues(object entity, object[] values) + { + throw new NotImplementedException(); + } + + public object GetPropertyValue(object entity, int i) + { + throw new NotImplementedException(); + } + + public object Instantiate() + { + throw new NotImplementedException(); + } + + public bool IsInstance(object obj) + { + throw new NotImplementedException(); + } + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-02-07 04:34:49 UTC (rev 4064) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-02-07 04:59:58 UTC (rev 4065) @@ -394,6 +394,7 @@ <Compile Include="NHSpecificTest\Dates\FixtureBase.cs" /> <Compile Include="NHSpecificTest\Dates\DateTime2Fixture.cs" /> <Compile Include="NHSpecificTest\Dates\DateTimeAssert.cs" /> + <Compile Include="NHSpecificTest\EntityModeToTuplizerPerf\Fixture.cs" /> <Compile Include="NHSpecificTest\FileStreamSql2008\VendorCatalog.cs" /> <Compile Include="NHSpecificTest\FileStreamSql2008\Fixture.cs" /> <Compile Include="NHSpecificTest\FileStreamSql2008\Convert.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |