diff --git a/src/NHibernate.Test/Async/Hql/HQLFunctions.cs b/src/NHibernate.Test/Async/Hql/HQLFunctions.cs index d5ea20b1681..e09e5a426ba 100644 --- a/src/NHibernate.Test/Async/Hql/HQLFunctions.cs +++ b/src/NHibernate.Test/Async/Hql/HQLFunctions.cs @@ -1079,9 +1079,9 @@ public async Task Current_DateAsync() public async Task Current_Date_IsLowestTimeOfDayAsync() { AssumeFunctionSupported("current_date"); - var now = DateTime.Now; if (!TestDialect.SupportsNonDataBoundCondition) Assert.Ignore("Test is not supported by the target database"); + var now = DateTime.Now; if (now.TimeOfDay < TimeSpan.FromMinutes(5) || now.TimeOfDay > TimeSpan.Parse("23:55")) Assert.Ignore("Test is unreliable around midnight"); diff --git a/src/NHibernate/Linq/Functions/DefaultLinqToHqlGeneratorsRegistry.cs b/src/NHibernate/Linq/Functions/DefaultLinqToHqlGeneratorsRegistry.cs index 2a694a9294a..ea5ab8a159c 100644 --- a/src/NHibernate/Linq/Functions/DefaultLinqToHqlGeneratorsRegistry.cs +++ b/src/NHibernate/Linq/Functions/DefaultLinqToHqlGeneratorsRegistry.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System.Collections.Concurrent; +using System.Collections.Generic; using System.Linq; using System.Reflection; @@ -10,6 +11,9 @@ public class DefaultLinqToHqlGeneratorsRegistry : ILinqToHqlGeneratorsRegistry private readonly Dictionary registeredProperties = new Dictionary(); private readonly List runtimeMethodHqlGenerators = new List(); + private readonly ConcurrentDictionary _cachedRuntimeMethodHqlGenerators = + new ConcurrentDictionary(); + public DefaultLinqToHqlGeneratorsRegistry() { RegisterGenerator(new StandardLinqExtensionMethodGenerator()); @@ -69,14 +73,15 @@ public DefaultLinqToHqlGeneratorsRegistry() protected bool GetRuntimeMethodGenerator(MethodInfo method, out IHqlGeneratorForMethod methodGenerator) { - methodGenerator = null; - - foreach (var typeGenerator in runtimeMethodHqlGenerators.Where(typeGenerator => typeGenerator.SupportsMethod(method))) - { - methodGenerator = typeGenerator.GetMethodGenerator(method); - return true; - } - return false; + methodGenerator = _cachedRuntimeMethodHqlGenerators.GetOrAdd( + method, + m => + runtimeMethodHqlGenerators + .Where(g => g.SupportsMethod(m)) + .Select(g => g.GetMethodGenerator(m)) + .FirstOrDefault()); + + return methodGenerator != null; } public virtual bool TryGetGenerator(MethodInfo method, out IHqlGeneratorForMethod generator) @@ -112,6 +117,7 @@ public virtual void RegisterGenerator(MemberInfo property, IHqlGeneratorForPrope public void RegisterGenerator(IRuntimeMethodHqlGenerator generator) { runtimeMethodHqlGenerators.Add(generator); + _cachedRuntimeMethodHqlGenerators.Clear(); } } }