From 19334ede058f1196a4e5a8d091251c9aea62ee30 Mon Sep 17 00:00:00 2001 From: Sergei Pavlov Date: Thu, 30 Oct 2025 11:09:50 -0700 Subject: [PATCH 1/2] Use covariant types in `BindParameter()` --- .../Orm/Linq/Expressions/ColumnExpression.cs | 8 +++----- .../Orm/Linq/Expressions/ConstructorExpression.cs | 2 +- .../Orm/Linq/Expressions/EntityExpression.cs | 8 ++++---- .../Orm/Linq/Expressions/EntityFieldExpression.cs | 4 ++-- .../Orm/Linq/Expressions/FullTextExpression.cs | 10 +++++----- .../Orm/Linq/Expressions/GroupingExpression.cs | 14 ++++++-------- .../Expressions/Interfaces/IMappedExpression.cs | 4 ++-- .../Orm/Linq/Expressions/KeyExpression.cs | 10 +--------- .../Linq/Expressions/LocalCollectionExpression.cs | 4 ++-- .../Linq/Expressions/ParameterizedExpression.cs | 4 ++-- .../Orm/Linq/Expressions/StructureExpression.cs | 6 +++--- .../Orm/Linq/Expressions/SubQueryExpression.cs | 6 ++---- .../Orm/Linq/Translator.Expressions.cs | 2 +- Orm/Xtensive.Orm/Orm/Linq/Translator.Queryable.cs | 2 +- 14 files changed, 35 insertions(+), 49 deletions(-) diff --git a/Orm/Xtensive.Orm/Orm/Linq/Expressions/ColumnExpression.cs b/Orm/Xtensive.Orm/Orm/Linq/Expressions/ColumnExpression.cs index a5905cd805..5a7fc7ccb8 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Expressions/ColumnExpression.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Expressions/ColumnExpression.cs @@ -32,10 +32,8 @@ public override ColumnExpression Remap(ColumnMap map, Dictionary()); - } + public ColumnExpression BindParameter(ParameterExpression parameter) => + BindParameter(parameter, new Dictionary()); public override ColumnExpression BindParameter(ParameterExpression parameter, Dictionary processedExpressions) { @@ -72,4 +70,4 @@ private ColumnExpression( this.Mapping = mapping; } } -} \ No newline at end of file +} diff --git a/Orm/Xtensive.Orm/Orm/Linq/Expressions/ConstructorExpression.cs b/Orm/Xtensive.Orm/Orm/Linq/Expressions/ConstructorExpression.cs index 9bdac3b965..5d53502ac8 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Expressions/ConstructorExpression.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Expressions/ConstructorExpression.cs @@ -28,7 +28,7 @@ internal sealed class ConstructorExpression : ParameterizedExpression public IReadOnlyList ConstructorArguments { get; } - public override Expression BindParameter(ParameterExpression parameter, Dictionary processedExpressions) + public override ParameterizedExpression BindParameter(ParameterExpression parameter, Dictionary processedExpressions) { GenericExpressionVisitor genericVisitor = new(mapped => mapped.BindParameter(parameter, processedExpressions)); var genericBinder = genericVisitor.Process; diff --git a/Orm/Xtensive.Orm/Orm/Linq/Expressions/EntityExpression.cs b/Orm/Xtensive.Orm/Orm/Linq/Expressions/EntityExpression.cs index 5742139a6a..8ccf75a7e3 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Expressions/EntityExpression.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Expressions/EntityExpression.cs @@ -76,13 +76,13 @@ public override EntityExpression Remap(ColumnMap map, Dictionary processedExpressions) + public override EntityExpression BindParameter(ParameterExpression parameter, Dictionary processedExpressions) { if (processedExpressions.TryGetValue(this, out var value)) { - return value; + return (EntityExpression) value; } - var keyExpression = (KeyExpression) Key.BindParameter(parameter, processedExpressions); + var keyExpression = Key.BindParameter(parameter, processedExpressions); var result = new EntityExpression(PersistentType, keyExpression, parameter, DefaultIfEmpty); result.IsNullable = IsNullable; processedExpressions.Add(this, result); @@ -177,7 +177,7 @@ public static EntityExpression Create(EntityFieldExpression entityFieldExpressio result.SetFields(fields); return entityFieldExpression.OuterParameter == null ? result - : (EntityExpression) result.BindParameter( + : result.BindParameter( entityFieldExpression.OuterParameter, new Dictionary()); } diff --git a/Orm/Xtensive.Orm/Orm/Linq/Expressions/EntityFieldExpression.cs b/Orm/Xtensive.Orm/Orm/Linq/Expressions/EntityFieldExpression.cs index 79bfb7aabf..483bd2d395 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Expressions/EntityFieldExpression.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Expressions/EntityFieldExpression.cs @@ -109,8 +109,8 @@ public override EntityFieldExpression BindParameter( // Do not convert to LINQ. We want to avoid a closure creation here. newFields[i++] = (PersistentFieldExpression) field.BindParameter(parameter, processedExpressions); } - var keyExpression = (KeyExpression) Key.BindParameter(parameter, processedExpressions); - var entity = (EntityExpression) Entity?.BindParameter(parameter, processedExpressions); + var keyExpression = Key.BindParameter(parameter, processedExpressions); + var entity = Entity?.BindParameter(parameter, processedExpressions); var result = new EntityFieldExpression( PersistentType, Field, newFields, Mapping, keyExpression, entity, parameter, DefaultIfEmpty); if (Owner == null) { diff --git a/Orm/Xtensive.Orm/Orm/Linq/Expressions/FullTextExpression.cs b/Orm/Xtensive.Orm/Orm/Linq/Expressions/FullTextExpression.cs index 4a8428177a..88a6142b9a 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Expressions/FullTextExpression.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Expressions/FullTextExpression.cs @@ -24,14 +24,14 @@ internal sealed class FullTextExpression : ParameterizedExpression public EntityExpression EntityExpression { get; private set; } - public override Expression BindParameter(ParameterExpression parameter, Dictionary processedExpressions) + public override ParameterizedExpression BindParameter(ParameterExpression parameter, Dictionary processedExpressions) { Expression result; if (processedExpressions.TryGetValue(this, out result)) - return result; + return (ParameterizedExpression) result; - var entityExpression = (EntityExpression) EntityExpression.BindParameter(parameter, processedExpressions); - var rankExpression = (ColumnExpression) RankExpression.BindParameter(parameter, processedExpressions); + var entityExpression = EntityExpression.BindParameter(parameter, processedExpressions); + var rankExpression = RankExpression.BindParameter(parameter, processedExpressions); return new FullTextExpression(FullTextIndex, entityExpression, rankExpression, parameter); } @@ -84,4 +84,4 @@ public FullTextExpression(FullTextIndexInfo fullTextIndex, EntityExpression enti EntityExpression = entityExpression; } } -} \ No newline at end of file +} diff --git a/Orm/Xtensive.Orm/Orm/Linq/Expressions/GroupingExpression.cs b/Orm/Xtensive.Orm/Orm/Linq/Expressions/GroupingExpression.cs index 4dae2b297d..40d9559946 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Expressions/GroupingExpression.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Expressions/GroupingExpression.cs @@ -42,16 +42,14 @@ public SelectManyGroupingInfo(ProjectionExpression groupByProjection) public SelectManyGroupingInfo SelectManyInfo { get; private set; } - public override Expression BindParameter(ParameterExpression parameter, Dictionary processedExpressions) + public override ParameterizedExpression BindParameter(ParameterExpression parameter, Dictionary processedExpressions) { - Expression result; - if (processedExpressions.TryGetValue(this, out result)) - return result; - var mappedKey = KeyExpression as IMappedExpression; - if (mappedKey==null) + if (processedExpressions.TryGetValue(this, out var value)) + return (ParameterizedExpression) value; + if (!(KeyExpression is IMappedExpression mappedKey)) return this; var processedKey = mappedKey.BindParameter(parameter, processedExpressions); - result = new GroupingExpression(Type, OuterParameter, DefaultIfEmpty, ProjectionExpression, ApplyParameter, processedKey, SelectManyInfo); + var result = new GroupingExpression(Type, OuterParameter, DefaultIfEmpty, ProjectionExpression, ApplyParameter, processedKey, SelectManyInfo); processedExpressions.Add(this, result); return result; } @@ -110,4 +108,4 @@ public GroupingExpression( KeyExpression = keyExpression; } } -} \ No newline at end of file +} diff --git a/Orm/Xtensive.Orm/Orm/Linq/Expressions/Interfaces/IMappedExpression.cs b/Orm/Xtensive.Orm/Orm/Linq/Expressions/Interfaces/IMappedExpression.cs index c290cd3a4f..57f1ecda5b 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Expressions/Interfaces/IMappedExpression.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Expressions/Interfaces/IMappedExpression.cs @@ -12,9 +12,9 @@ namespace Xtensive.Orm.Linq.Expressions { internal interface IMappedExpression { - Expression BindParameter(ParameterExpression parameter, Dictionary processedExpressions); + ParameterizedExpression BindParameter(ParameterExpression parameter, Dictionary processedExpressions); Expression RemoveOuterParameter(Dictionary processedExpressions); Expression Remap(ColNum offset, Dictionary processedExpressions); Expression Remap(ColumnMap map, Dictionary processedExpressions); } -} \ No newline at end of file +} diff --git a/Orm/Xtensive.Orm/Orm/Linq/Expressions/KeyExpression.cs b/Orm/Xtensive.Orm/Orm/Linq/Expressions/KeyExpression.cs index 9a0ddc7048..612026261c 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Expressions/KeyExpression.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Expressions/KeyExpression.cs @@ -79,14 +79,6 @@ public override KeyExpression BindParameter( return (KeyExpression)value; } - return BindParameterWithNoCheck(parameter, processedExpressions); - } - - // Having this code as a separate method helps to avoid closure allocation during BindParameter call - // in case processedExpressions dictionary already contains a result. - private KeyExpression BindParameterWithNoCheck( - ParameterExpression parameter, Dictionary processedExpressions) - { var n = KeyFields.Count; var fields = new FieldExpression[n]; for (int i = 0; i < n; ++i) { @@ -155,4 +147,4 @@ private KeyExpression( KeyFields = keyFields; } } -} \ No newline at end of file +} diff --git a/Orm/Xtensive.Orm/Orm/Linq/Expressions/LocalCollectionExpression.cs b/Orm/Xtensive.Orm/Orm/Linq/Expressions/LocalCollectionExpression.cs index c62454e0d6..4ad22edeb1 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Expressions/LocalCollectionExpression.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Expressions/LocalCollectionExpression.cs @@ -54,10 +54,10 @@ public override Expression Remap(ColumnMap map, Dictionary processedExpressions) + public override ParameterizedExpression BindParameter(ParameterExpression parameter, Dictionary processedExpressions) { if (processedExpressions.TryGetValue(this, out var value)) - return value; + return (ParameterizedExpression) value; var result = new LocalCollectionExpression(Type, MemberInfo, expressionAsString); processedExpressions.Add(this, result); diff --git a/Orm/Xtensive.Orm/Orm/Linq/Expressions/ParameterizedExpression.cs b/Orm/Xtensive.Orm/Orm/Linq/Expressions/ParameterizedExpression.cs index 300f0be960..65c9b10c3f 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Expressions/ParameterizedExpression.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Expressions/ParameterizedExpression.cs @@ -42,7 +42,7 @@ protected bool TryProcessed(Dictionary processedExpre return false; } - public abstract Expression BindParameter(ParameterExpression parameter, Dictionary processedExpressions); + public abstract ParameterizedExpression BindParameter(ParameterExpression parameter, Dictionary processedExpressions); public abstract Expression RemoveOuterParameter(Dictionary processedExpressions); public abstract Expression Remap(ColNum offset, Dictionary processedExpressions); public abstract Expression Remap(ColumnMap map, Dictionary processedExpressions); @@ -56,4 +56,4 @@ protected ParameterizedExpression(ExtendedExpressionType expressionType, Type ty DefaultIfEmpty = defaultIfEmpty; } } -} \ No newline at end of file +} diff --git a/Orm/Xtensive.Orm/Orm/Linq/Expressions/StructureExpression.cs b/Orm/Xtensive.Orm/Orm/Linq/Expressions/StructureExpression.cs index d696eb3c43..8b28a6f50f 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Expressions/StructureExpression.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Expressions/StructureExpression.cs @@ -88,10 +88,10 @@ public override Expression Remap(ColumnMap map, Dictionary processedExpressions) + public override ParameterizedExpression BindParameter(ParameterExpression parameter, Dictionary processedExpressions) { if (processedExpressions.TryGetValue(this, out var value)) { - return value; + return (ParameterizedExpression) value; } var result = new StructureExpression(PersistentType, Mapping); @@ -172,4 +172,4 @@ private StructureExpression( PersistentType = persistentType; } } -} \ No newline at end of file +} diff --git a/Orm/Xtensive.Orm/Orm/Linq/Expressions/SubQueryExpression.cs b/Orm/Xtensive.Orm/Orm/Linq/Expressions/SubQueryExpression.cs index bdc0ee7e03..459898f577 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Expressions/SubQueryExpression.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Expressions/SubQueryExpression.cs @@ -22,10 +22,8 @@ internal class SubQueryExpression : ParameterizedExpression public ApplyParameter ApplyParameter { get; } - public override Expression BindParameter(ParameterExpression parameter, Dictionary processedExpressions) - { - return this; - } + public override ParameterizedExpression BindParameter(ParameterExpression parameter, Dictionary processedExpressions) => + this; public override Expression RemoveOuterParameter(Dictionary processedExpressions) { diff --git a/Orm/Xtensive.Orm/Orm/Linq/Translator.Expressions.cs b/Orm/Xtensive.Orm/Orm/Linq/Translator.Expressions.cs index f2c40ed163..57a70b1f1c 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Translator.Expressions.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Translator.Expressions.cs @@ -1704,7 +1704,7 @@ private Expression VisitTypeAs(Expression source, Type targetType) var result = EntityExpression.Create(targetTypeInfo, offset, false); result.IsNullable = true; if (parameter != currentParameter) { - result = (EntityExpression) result.BindParameter(parameter, new Dictionary()); + result = result.BindParameter(parameter, new Dictionary()); } return result; diff --git a/Orm/Xtensive.Orm/Orm/Linq/Translator.Queryable.cs b/Orm/Xtensive.Orm/Orm/Linq/Translator.Queryable.cs index f2a06990bd..7f9aad3457 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Translator.Queryable.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Translator.Queryable.cs @@ -847,7 +847,7 @@ private Expression VisitAggregate(Expression source, MethodInfo method, LambdaEx var resultColumn = ColumnExpression.Create(columnType, (ColNum) (resultDataSource.Header.Length - 1)); if (isSubqueryParameter) { - resultColumn = (ColumnExpression) resultColumn.BindParameter(groupingParameter); + resultColumn = resultColumn.BindParameter(groupingParameter); } return convertResultColumn ? Expression.Convert(resultColumn, resultType) : (Expression) resultColumn; } From 3291afefc4a64118cecb30a642a05eaa048f435e Mon Sep 17 00:00:00 2001 From: Sergei Pavlov Date: Thu, 30 Oct 2025 11:32:39 -0700 Subject: [PATCH 2/2] Continue --- .../Orm/Linq/Expressions/ColumnExpression.cs | 6 ++--- .../Orm/Linq/Expressions/EntityExpression.cs | 6 ++--- .../Linq/Expressions/EntityFieldExpression.cs | 27 +++++++++---------- .../Linq/Expressions/EntitySetExpression.cs | 11 ++++---- .../Orm/Linq/Expressions/FieldExpression.cs | 8 +++--- .../Linq/Expressions/FullTextExpression.cs | 4 +-- .../Orm/Linq/Expressions/KeyExpression.cs | 20 +++----------- .../Expressions/ParameterizedExpression.cs | 2 -- .../Expressions/StructureFieldExpression.cs | 7 ++--- 9 files changed, 34 insertions(+), 57 deletions(-) diff --git a/Orm/Xtensive.Orm/Orm/Linq/Expressions/ColumnExpression.cs b/Orm/Xtensive.Orm/Orm/Linq/Expressions/ColumnExpression.cs index 5a7fc7ccb8..9f538905cc 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Expressions/ColumnExpression.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Expressions/ColumnExpression.cs @@ -40,10 +40,8 @@ public override ColumnExpression BindParameter(ParameterExpression parameter, Di return new ColumnExpression(Type, Mapping, parameter, DefaultIfEmpty); } - public override Expression RemoveOuterParameter(Dictionary processedExpressions) - { - return new ColumnExpression(Type, Mapping, null, DefaultIfEmpty); - } + public override ColumnExpression RemoveOuterParameter(Dictionary processedExpressions) => + new(Type, Mapping, null, DefaultIfEmpty); public static ColumnExpression Create(Type type, ColNum columnIndex) { diff --git a/Orm/Xtensive.Orm/Orm/Linq/Expressions/EntityExpression.cs b/Orm/Xtensive.Orm/Orm/Linq/Expressions/EntityExpression.cs index 8ccf75a7e3..c59ccac856 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Expressions/EntityExpression.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Expressions/EntityExpression.cs @@ -96,13 +96,13 @@ public override EntityExpression BindParameter(ParameterExpression parameter, Di return result; } - public override Expression RemoveOuterParameter(Dictionary processedExpressions) + public override EntityExpression RemoveOuterParameter(Dictionary processedExpressions) { if (processedExpressions.TryGetValue(this, out var value)) { - return value; + return (EntityExpression) value; } - var keyExpression = (KeyExpression) Key.RemoveOuterParameter(processedExpressions); + var keyExpression = Key.RemoveOuterParameter(processedExpressions); var result = new EntityExpression(PersistentType, keyExpression, null, DefaultIfEmpty); result.IsNullable = IsNullable; processedExpressions.Add(this, result); diff --git a/Orm/Xtensive.Orm/Orm/Linq/Expressions/EntityFieldExpression.cs b/Orm/Xtensive.Orm/Orm/Linq/Expressions/EntityFieldExpression.cs index 483bd2d395..70de184c59 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Expressions/EntityFieldExpression.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Expressions/EntityFieldExpression.cs @@ -4,8 +4,6 @@ // Created by: Alexis Kochetov // Created: 2009.05.06 -using System; -using System.Collections.Generic; using System.Linq.Expressions; using Xtensive.Core; using Xtensive.Orm.Model; @@ -103,11 +101,11 @@ public override EntityFieldExpression BindParameter( return (EntityFieldExpression)r; } - var newFields = new PersistentFieldExpression[fields.Count]; - int i = 0; - foreach (var field in fields) { + var n = fields.Count; + var newFields = new PersistentFieldExpression[n]; + for (int i = 0; i < n; ++i) { // Do not convert to LINQ. We want to avoid a closure creation here. - newFields[i++] = (PersistentFieldExpression) field.BindParameter(parameter, processedExpressions); + newFields[i] = (PersistentFieldExpression) fields[i].BindParameter(parameter, processedExpressions); } var keyExpression = Key.BindParameter(parameter, processedExpressions); var entity = Entity?.BindParameter(parameter, processedExpressions); @@ -122,20 +120,21 @@ public override EntityFieldExpression BindParameter( return result; } - public override Expression RemoveOuterParameter(Dictionary processedExpressions) + public override EntityFieldExpression RemoveOuterParameter(Dictionary processedExpressions) { - if (processedExpressions.TryGetValue(this, out var result)) { - return result; + if (processedExpressions.TryGetValue(this, out var value)) { + return (EntityFieldExpression) value; } - var newFields = new List(fields.Count); + var newFields = new PersistentFieldExpression[fields.Count]; + int i = 0; foreach (var field in fields) { // Do not convert to LINQ. We want to avoid a closure creation here. - newFields.Add((PersistentFieldExpression) field.RemoveOuterParameter(processedExpressions)); + newFields[i++] = (PersistentFieldExpression) field.RemoveOuterParameter(processedExpressions); } - var keyExpression = (KeyExpression) Key.RemoveOuterParameter(processedExpressions); - var entity = (EntityExpression) Entity?.RemoveOuterParameter(processedExpressions); - result = new EntityFieldExpression( + var keyExpression = Key.RemoveOuterParameter(processedExpressions); + var entity = Entity?.RemoveOuterParameter(processedExpressions); + var result = new EntityFieldExpression( PersistentType, Field, newFields, Mapping, keyExpression, entity, null, DefaultIfEmpty); if (Owner == null) { return result; diff --git a/Orm/Xtensive.Orm/Orm/Linq/Expressions/EntitySetExpression.cs b/Orm/Xtensive.Orm/Orm/Linq/Expressions/EntitySetExpression.cs index 8fd58142da..67459302ee 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Expressions/EntitySetExpression.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Expressions/EntitySetExpression.cs @@ -87,12 +87,11 @@ public override EntitySetExpression BindParameter(ParameterExpression parameter, return result; } - public override Expression RemoveOuterParameter(Dictionary processedExpressions) + public override EntitySetExpression RemoveOuterParameter(Dictionary processedExpressions) { - Expression result; - if (processedExpressions.TryGetValue(this, out result)) - return result; - result = new EntitySetExpression(Field, null, DefaultIfEmpty); + if (processedExpressions.TryGetValue(this, out var value)) + return (EntitySetExpression) value; + var result = new EntitySetExpression(Field, null, DefaultIfEmpty); if (base.Owner==null) return result; processedExpressions.Add(this, result); @@ -122,4 +121,4 @@ private EntitySetExpression( { } } -} \ No newline at end of file +} diff --git a/Orm/Xtensive.Orm/Orm/Linq/Expressions/FieldExpression.cs b/Orm/Xtensive.Orm/Orm/Linq/Expressions/FieldExpression.cs index e92eb352a8..d9a149e5aa 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Expressions/FieldExpression.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Expressions/FieldExpression.cs @@ -90,13 +90,13 @@ public override FieldExpression BindParameter(ParameterExpression parameter, Dic return result; } - public override Expression RemoveOuterParameter(Dictionary processedExpressions) + public override FieldExpression RemoveOuterParameter(Dictionary processedExpressions) { - if (processedExpressions.TryGetValue(this, out var result)) { - return result; + if (processedExpressions.TryGetValue(this, out var value)) { + return (FieldExpression) value; } - result = new FieldExpression(ExtendedExpressionType.Field, Field, Mapping, null, DefaultIfEmpty); + var result = new FieldExpression(ExtendedExpressionType.Field, Field, Mapping, null, DefaultIfEmpty); if (owner == null) { return result; } diff --git a/Orm/Xtensive.Orm/Orm/Linq/Expressions/FullTextExpression.cs b/Orm/Xtensive.Orm/Orm/Linq/Expressions/FullTextExpression.cs index 88a6142b9a..b7389ca9bd 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Expressions/FullTextExpression.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Expressions/FullTextExpression.cs @@ -41,8 +41,8 @@ public override Expression RemoveOuterParameter(Dictionary(processedExpressions, out var value)) return value; - return RemapWithNoCheck(offset, processedExpressions); - } - - // Having this code as a separate method helps to avoid closure allocation during Remap call - // in case processedExpressions dictionary already contains a result. - private KeyExpression RemapWithNoCheck(ColNum offset, Dictionary processedExpressions) - { var newMapping = new Segment((ColNum)(Mapping.Offset + offset), Mapping.Length); var n = KeyFields.Count; @@ -90,23 +83,16 @@ public override KeyExpression BindParameter( return result; } - public override Expression RemoveOuterParameter(Dictionary processedExpressions) + public override KeyExpression RemoveOuterParameter(Dictionary processedExpressions) { if (processedExpressions.TryGetValue(this, out var value)) { - return value; + return (KeyExpression) value; } - return RemoveOuterParameterWithNoCheck(processedExpressions); - } - - // Having this code as a separate method helps to avoid closure allocation during RemoveOuterParameter call - // in case processedExpressions dictionary already contains a result. - private Expression RemoveOuterParameterWithNoCheck(Dictionary processedExpressions) - { var n = KeyFields.Count; var fields = new FieldExpression[n]; for (int i = 0; i < n; ++i) { - fields[i] = (FieldExpression) KeyFields[i].RemoveOuterParameter(processedExpressions); + fields[i] = KeyFields[i].RemoveOuterParameter(processedExpressions); } var result = new KeyExpression(EntityType, fields, Mapping, UnderlyingProperty, null, DefaultIfEmpty); diff --git a/Orm/Xtensive.Orm/Orm/Linq/Expressions/ParameterizedExpression.cs b/Orm/Xtensive.Orm/Orm/Linq/Expressions/ParameterizedExpression.cs index 65c9b10c3f..7ed9dd64e7 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Expressions/ParameterizedExpression.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Expressions/ParameterizedExpression.cs @@ -4,8 +4,6 @@ // Created by: Alexis Kochetov // Created: 2009.05.18 -using System; -using System.Collections.Generic; using System.Linq.Expressions; namespace Xtensive.Orm.Linq.Expressions diff --git a/Orm/Xtensive.Orm/Orm/Linq/Expressions/StructureFieldExpression.cs b/Orm/Xtensive.Orm/Orm/Linq/Expressions/StructureFieldExpression.cs index d4e6cb5f97..c5f0175cb1 100644 --- a/Orm/Xtensive.Orm/Orm/Linq/Expressions/StructureFieldExpression.cs +++ b/Orm/Xtensive.Orm/Orm/Linq/Expressions/StructureFieldExpression.cs @@ -4,9 +4,6 @@ // Created by: Alexis Kochetov // Created: 2009.05.05 -using System; -using System.Collections.Generic; -using System.Linq; using System.Linq.Expressions; using Xtensive.Core; using Xtensive.Orm.Model; @@ -120,10 +117,10 @@ public override StructureFieldExpression BindParameter(ParameterExpression param return result; } - public override Expression RemoveOuterParameter(Dictionary processedExpressions) + public override StructureFieldExpression RemoveOuterParameter(Dictionary processedExpressions) { if (processedExpressions.TryGetValue(this, out var value)) { - return value; + return (StructureFieldExpression) value; } var result = new StructureFieldExpression(PersistentType, Field, Mapping, OuterParameter, DefaultIfEmpty);