Skip to content

Commit ef48c06

Browse files
committed
Optimize MakeGenericMethod() invocations for generics
1 parent 5a387a6 commit ef48c06

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

Orm/Xtensive.Orm/Orm/QueryableExtensions.cs

+14-9
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,8 @@
44
// Created by: Alexey Gamzov
55
// Created: 2009.05.06
66

7-
using System;
8-
using System.Collections.Generic;
9-
using System.Linq;
107
using System.Linq.Expressions;
11-
using System.Threading;
12-
using System.Threading.Tasks;
8+
using System.Reflection;
139
using JetBrains.Annotations;
1410
using Xtensive.Core;
1511
using Xtensive.Orm.Internals;
@@ -23,6 +19,17 @@ namespace Xtensive.Orm
2319
/// </summary>
2420
public static partial class QueryableExtensions
2521
{
22+
private static class Traits<T>
23+
{
24+
public static readonly MethodInfo ExtensionTagMethodInfo = WellKnownMembers.Queryable.ExtensionTag.MakeGenericMethod([typeof(T)]);
25+
}
26+
27+
private static class Traits<TOuter, TInner, TKey, TResult>
28+
{
29+
public static readonly MethodInfo ExtensionLeftJoinMethodInfo
30+
= WellKnownMembers.Queryable.ExtensionLeftJoin.MakeGenericMethod([typeof (TOuter), typeof(TInner), typeof(TKey), typeof(TResult)]);
31+
}
32+
2633
/// <summary>
2734
/// Tags query with given <paramref name="tag"/> string
2835
/// (inserts string as comment in SQL statement) for
@@ -43,8 +50,7 @@ public static IQueryable<TSource> Tag<TSource>(this IQueryable<TSource> source,
4350
throw new NotSupportedException(string.Format(errorMessage, providerType));
4451
}
4552

46-
var genericMethod = WellKnownMembers.Queryable.ExtensionTag.MakeGenericMethod(new[] { typeof(TSource) });
47-
var expression = Expression.Call(null, genericMethod, new[] { source.Expression, Expression.Constant(tag)});
53+
var expression = Expression.Call(null, Traits<TSource>.ExtensionTagMethodInfo, new[] { source.Expression, Expression.Constant(tag)});
4854
return source.Provider.CreateQuery<TSource>(expression);
4955
}
5056

@@ -340,8 +346,7 @@ public static IQueryable<TResult> LeftOuterJoin<TOuter, TInner, TKey, TResult>(t
340346
throw new NotSupportedException(string.Format(errorMessage, outerProviderType));
341347
}
342348

343-
var genericMethod = WellKnownMembers.Queryable.ExtensionLeftJoin.MakeGenericMethod(new[] {typeof (TOuter), typeof(TInner), typeof(TKey), typeof(TResult)});
344-
var expression = Expression.Call(null, genericMethod, new[] {outer.Expression, GetSourceExpression(inner), outerKeySelector, innerKeySelector, resultSelector});
349+
var expression = Expression.Call(null, Traits<TOuter, TInner, TKey, TResult>.ExtensionLeftJoinMethodInfo, new[] {outer.Expression, GetSourceExpression(inner), outerKeySelector, innerKeySelector, resultSelector});
345350
return outer.Provider.CreateQuery<TResult>(expression);
346351
}
347352

0 commit comments

Comments
 (0)