Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
70845b6
ParameterBinding normalization use arrays instead of HashSet
alex-kulakov Apr 11, 2024
4c3fa06
CommandFactory Improvements
alex-kulakov Apr 11, 2024
ad2daf4
QueryTranslationResult moves List creation to the caller
alex-kulakov Apr 11, 2024
5209a39
Persist sequence of SqlPersistTask is now IReadOnlyCollection
alex-kulakov Apr 11, 2024
646cb07
CommandFactory: Prevent copying string parameter that never change
alex-kulakov Apr 12, 2024
46e47a0
Enumerable.Range() usages improved
alex-kulakov Apr 22, 2024
b464f71
Use cached MethodInfo
alex-kulakov Apr 22, 2024
06d5cf5
IPostCompiler/IPrecompiler visitors revised
alex-kulakov Apr 22, 2024
f51475a
Dictionary.ContainsKey replaced with TryGetValue/TryAdd/TryRemove
alex-kulakov Apr 23, 2024
387bbcb
SqlCompiler improvements
alex-kulakov Apr 24, 2024
8b68947
Linq translator improvements
alex-kulakov Apr 24, 2024
6ef8cc8
Linq.Translator improvements
alex-kulakov Apr 26, 2024
0e95fb8
More enumeration improvements
alex-kulakov Apr 28, 2024
96cfe99
Use WellKnown.KeyFieldName instead of literal
alex-kulakov Apr 30, 2024
f214e54
Cached TupleParameter
alex-kulakov Apr 30, 2024
65941e7
Translator.Translate(ProjectionExpression, IEnumerable<Parameter<Tupl…
alex-kulakov Apr 30, 2024
b1b1c29
Remove commented code
alex-kulakov May 2, 2024
5c25e73
MaterializationContext: improved way to build typeColumnMap
alex-kulakov May 3, 2024
5bcabe7
Getting getter method of indexer property improved
alex-kulakov May 3, 2024
3789b53
Less enumerations and memory used
alex-kulakov May 3, 2024
f2283c9
Add cache of root method call expressions
alex-kulakov May 15, 2024
c311e8c
Small improvements
alex-kulakov May 15, 2024
ff2ff6b
ValueFieldAccessorResolver: Getting value accessors re-arranged
alex-kulakov May 24, 2024
612f788
File summary updated
alex-kulakov May 27, 2024
bee6405
SqlServer.ErrorMessageParser: remove copying to array
alex-kulakov May 27, 2024
db538f3
AggregateProvider and CalculateProvider saves some time and memory
alex-kulakov May 28, 2024
30441d6
ReverseList() instead of List.Reverse() for clear enumeration purposes
alex-kulakov May 28, 2024
6321d2c
IndexBuilder.SingleTable: Remove .ToList(), no need for enumeration
alex-kulakov May 28, 2024
79d4ddb
Accidental things, which were left during experiments, removed
alex-kulakov May 29, 2024
4af537f
Changlog improved
alex-kulakov May 29, 2024
0973d9e
Postgre extractor issue fixed
alex-kulakov May 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ChangeLog/7.0.5_dev.txt
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
[main] Updated BitFaster.Caching package
[main] Some constructors of SqlPersistTask marked Obsolete, new constructors provided
[main] Some constructors of CalculateProvider marked Obsolete, new constructors provided
[main] Some constructors of AggregateProvider marked Obsolete, new constructors provided
[main] Updated BitFaster.Caching package
[main] Certain optimizations connected to query translation made
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2003-2023 Xtensive LLC.
// Copyright (C) 2003-2024 Xtensive LLC.
// This code is distributed under MIT license terms.
// See the License.txt file in the project root for more information.

Expand Down Expand Up @@ -718,14 +718,14 @@ protected virtual void ReadColumnData(DbDataReader dataReader, ExtractionContext
var columnOwnerId = Convert.ToInt64(dataReader["attrelid"]);
var columnId = Convert.ToInt64(dataReader["attnum"]);
var columnName = dataReader["attname"].ToString();
if (tableMap.ContainsKey(columnOwnerId)) {
var table = tableMap[columnOwnerId];
if (tableMap.TryGetValue(columnOwnerId, out var table)) {
var col = table.CreateColumn(columnName);
if (!tableColumns.ContainsKey(columnOwnerId)) {
tableColumns.Add(columnOwnerId, new Dictionary<long, TableColumn>());
if (tableColumns.TryGetValue(columnOwnerId, out var columns)) {
columns.Add(columnId, col);
}
else {
tableColumns.Add(columnOwnerId, new Dictionary<long, TableColumn>() { { columnId, col } });
}

tableColumns[columnOwnerId].Add(columnId, col);

var columnTypeName = dataReader["typname"].ToString();
var columnTypeSpecificData = Convert.ToInt32(dataReader["atttypmod"]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ public sealed class ErrorMessageParser
private sealed class PreparedTemplate
{
public readonly Regex ParserExpression;
public readonly ReadOnlyCollection<int> Indexes;
public readonly IReadOnlyList<int> Indexes;

public PreparedTemplate(string regex, IEnumerable<int> indexes)
public PreparedTemplate(string regex, IReadOnlyList<int> indexes)
{
ParserExpression = new Regex(regex, RegexOptions.Compiled | RegexOptions.CultureInvariant);
Indexes = indexes.ToList().AsReadOnly();
Indexes = indexes;
}
}

Expand Down Expand Up @@ -190,7 +190,7 @@ private static PreparedTemplate PrepareEnglishTemplate(string template)
}

CollectLastChunk(regexBuilder, template, offset);
return new PreparedTemplate(regexBuilder.ToString(), Enumerable.Range(1, count));
return new PreparedTemplate(regexBuilder.ToString(), Enumerable.Range(1, count).ToArray(count));
}

private static PreparedTemplate PrepareNonEnglishTemplate(string template)
Expand Down
4 changes: 2 additions & 2 deletions Orm/Xtensive.Orm/Core/Extensions/EnumerableExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2008-2021 Xtensive LLC.
// Copyright (C) 2008-2024 Xtensive LLC.
// This code is distributed under MIT license terms.
// See the License.txt file in the project root for more information.
// Created by: Alex Yakunin
Expand Down Expand Up @@ -601,7 +601,7 @@ public static List<TValue> SortTopologically<TValue>(this IEnumerable<TValue> va
if (edgeTester.Invoke(left.Value, right.Value))
new Edge(left, right);
var result = TopologicalSorter.Sort(graph);
return result.HasLoops ? null : result.SortedNodes.Select(node => node.Value).ToList();
return result.HasLoops ? null : result.SortedNodes.SelectToList(node => node.Value);
}

/// <summary>
Expand Down
14 changes: 7 additions & 7 deletions Orm/Xtensive.Orm/Linq/Internals/ExpressionComparer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2009-2020 Xtensive LLC.
// Copyright (C) 2009-2024 Xtensive LLC.
// This code is distributed under MIT license terms.
// See the License.txt file in the project root for more information.
// Created by: Denis Krjuchkov
Expand Down Expand Up @@ -111,7 +111,7 @@ private bool VisitListInit(ListInitExpression x, ListInitExpression y)
return VisitNew(x.NewExpression, y.NewExpression)
&& x.Initializers.Count==y.Initializers.Count
&& x.Initializers
.Zip(y.Initializers, (first, second) => new Pair<ElementInit>(first, second))
.Zip(y.Initializers)
.All(p => VisitElementInit(p.First, p.Second));
}

Expand All @@ -126,7 +126,7 @@ private bool VisitMemberInit(MemberInitExpression x, MemberInitExpression y)
return VisitNew(x.NewExpression, y.NewExpression)
&& x.Bindings.Count==y.Bindings.Count
&& x.Bindings
.Zip(y.Bindings, (first, second) => new Pair<MemberBinding>(first, second))
.Zip(y.Bindings)
.All(p => VisitMemberBinding(p.First, p.Second));
}

Expand All @@ -145,14 +145,14 @@ private bool VisitMemberBinding(MemberBinding x, MemberBinding y)
var mby = (MemberMemberBinding)y;
return mbx.Bindings.Count==mby.Bindings.Count
&& mbx.Bindings
.Zip(mby.Bindings, (first, second) => new Pair<MemberBinding>(first, second))
.Zip(mby.Bindings)
.All(p => VisitMemberBinding(p.First, p.Second));
case MemberBindingType.ListBinding:
var mlx = (MemberListBinding)x;
var mly = (MemberListBinding)y;
return mlx.Initializers.Count==mly.Initializers.Count
&& mlx.Initializers
.Zip(mly.Initializers, (first, second) => new Pair<ElementInit>(first, second))
.Zip(mly.Initializers)
.All(p => VisitElementInit(p.First, p.Second));
default:
throw new ArgumentOutOfRangeException();
Expand Down Expand Up @@ -189,7 +189,7 @@ private bool VisitNew(NewExpression x, NewExpression y)
return false;
if (x.Members.Count != y.Members.Count)
return false;
for (int i = 0; i < x.Members.Count; i++)
for (int i = 0, count = x.Members.Count; i < count; i++)
if (x.Members[i] != y.Members[i])
return false;
return true;
Expand Down Expand Up @@ -253,7 +253,7 @@ private bool CompareExpressionSequences<T>(
{
if (x.Count != y.Count)
return false;
for (int i = 0; i < x.Count; i++)
for (int i = 0, count = x.Count; i < count; i++)
if (!Visit(x[i], y[i]))
return false;
return true;
Expand Down
9 changes: 4 additions & 5 deletions Orm/Xtensive.Orm/Modelling/Actions/ActionSequence.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (C) 2003-2010 Xtensive LLC.
// All rights reserved.
// For conditions of distribution and use, see license.
// Copyright (C) 2009-2024 Xtensive LLC.
// This code is distributed under MIT license terms.
// See the License.txt file in the project root for more information.
// Created by: Alex Yakunin
// Created: 2009.03.23

Expand Down Expand Up @@ -51,8 +51,7 @@ public void Add(NodeAction action)
var last = actions[lastIndex] as PropertyChangeAction;
if (last!=null && ca.Path==last.Path) {
foreach (var pair in last.Properties) {
if (!ca.Properties.ContainsKey(pair.Key))
ca.Properties.Add(pair.Key, pair.Value);
_ = ca.Properties.TryAdd(pair.Key, pair.Value);
}
actions.RemoveAt(lastIndex);
}
Expand Down
10 changes: 5 additions & 5 deletions Orm/Xtensive.Orm/Modelling/Actions/CreateNodeAction.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (C) 2003-2010 Xtensive LLC.
// All rights reserved.
// For conditions of distribution and use, see license.
// Copyright (C) 2009-2024 Xtensive LLC.
// This code is distributed under MIT license terms.
// See the License.txt file in the project root for more information.
// Created by: Alex Yakunin
// Created: 2009.03.23

Expand Down Expand Up @@ -102,8 +102,8 @@ protected override void PerformExecute(IModel model, IPathNode item)
protected Node TryConstructor(IModel model, params object[] arguments)
{
if (parameters!=null)
arguments = arguments.Concat(parameters.Select(p => PathNodeReference.Resolve(model, p))).ToArray();
var argTypes = arguments.Select(a => a.GetType()).ToArray();
arguments = arguments.Concat(parameters.Select(p => PathNodeReference.Resolve(model, p))).ToArray(arguments.Length + parameters.Length);
var argTypes = arguments.SelectToArray(a => a.GetType());
var ci = type.GetConstructor(argTypes);
if (ci==null)
return null;
Expand Down
9 changes: 4 additions & 5 deletions Orm/Xtensive.Orm/Modelling/Actions/GroupingNodeAction.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (C) 2003-2010 Xtensive LLC.
// All rights reserved.
// For conditions of distribution and use, see license.
// Copyright (C) 2009-2024 Xtensive LLC.
// This code is distributed under MIT license terms.
// See the License.txt file in the project root for more information.
// Created by: Alex Yakunin
// Created: 2009.04.22

Expand Down Expand Up @@ -56,8 +56,7 @@ public void Add(NodeAction action)
var last = actions[lastIndex] as PropertyChangeAction;
if (last!=null && ca.Path==last.Path) {
foreach (var pair in last.Properties) {
if (!ca.Properties.ContainsKey(pair.Key))
ca.Properties.Add(pair.Key, pair.Value);
_ = ca.Properties.TryAdd(pair.Key, pair.Value);
}
actions.RemoveAt(lastIndex);
}
Expand Down
123 changes: 41 additions & 82 deletions Orm/Xtensive.Orm/Modelling/Comparison/Hints/HintSet.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (C) 2009-2021 Xtensive LLC.
// All rights reserved.
// For conditions of distribution and use, see license.
// Copyright (C) 2009-2024 Xtensive LLC.
// This code is distributed under MIT license terms.
// See the License.txt file in the project root for more information.
// Created by: Alex Yakunin
// Created: 2009.03.26

Expand Down Expand Up @@ -77,31 +77,25 @@ public void Add(Hint hint)
var nodes = new List<Node>();
foreach (var target in targets) {
Node node;
if (target.Model==ModelType.Source)
if (target.Model == ModelType.Source)
node = (Node) SourceModel.Resolve(target.Path, true);
else
node = (Node) TargetModel.Resolve(target.Path, true);
nodes.Add(node);

if (!hintMap.ContainsKey(node))
hintMap.Add(node, new Dictionary<Type, object>());
var nodeHintMap = hintMap[node];

var nodeHintMap = GetNodeHints(node);
var hintType = hint.GetType();

if (!nodeHintMap.ContainsKey(hintType))
nodeHintMap.Add(hintType, null);

var hintOrList = nodeHintMap[hintType];
if (hintOrList==null)
nodeHintMap[hintType] = hint;
else {
var list = hintOrList as List<Hint>;
if (list==null) {
var oldHint = (Hint) hintOrList;
nodeHintMap[hintType] = new List<Hint>(new[] {oldHint, hint});
}
else

if (nodeHintMap.TryGetValue(hintType, out var hintOrList)) {
if (hintOrList is List<Hint> list) {
list.Add(hint);
}
else {
nodeHintMap[hintType] = new List<Hint>(new[] { (Hint) hintOrList, hint });
}
}
else {
nodeHintMap.Add(hintType, hint);
}
}
}
Expand All @@ -126,46 +120,20 @@ public void Clear()

/// <inheritdoc/>
/// <exception cref="InvalidOperationException">Multiple hints found.</exception>
public THint GetHint<THint>(Node node)
where THint : Hint
{
ArgumentValidator.EnsureArgumentNotNull(node, "node");

if (!hintMap.ContainsKey(node))
hintMap.Add(node, new Dictionary<Type, object>());
var nodeHintMap = hintMap.GetValueOrDefault(node);
if (nodeHintMap==null)
return null;
var hintType = typeof(THint);
var hintOrList = nodeHintMap.GetValueOrDefault(hintType);
if (hintOrList==null)
return null;
var hint = hintOrList as THint;
if (hint!=null)
return hint;
throw new InvalidOperationException(Strings.ExMultipleHintsFound);
}
public THint GetHint<THint>(Node node) where THint : Hint =>
GetNodeHints(node).GetValueOrDefault(typeof(THint)) switch {
null => null,
THint hint => hint,
_ => throw new InvalidOperationException(Strings.ExMultipleHintsFound)
};

/// <inheritdoc/>
public THint[] GetHints<THint>(Node node)
where THint : Hint
{
ArgumentValidator.EnsureArgumentNotNull(node, "node");

if (!hintMap.ContainsKey(node))
hintMap.Add(node, new Dictionary<Type, object>());
var nodeHintMap = hintMap.GetValueOrDefault(node);
if (nodeHintMap==null)
return ArrayUtils<THint>.EmptyArray;
var hintType = typeof (THint);
var hintOrList = nodeHintMap.GetValueOrDefault(hintType);
if (hintOrList==null)
return ArrayUtils<THint>.EmptyArray;
var hint = hintOrList as THint;
if (hint!=null)
return new[] {hint};
return ((List<Hint>) hintOrList).Cast<THint>().ToArray();
}
public THint[] GetHints<THint>(Node node) where THint : Hint =>
GetNodeHints(node).GetValueOrDefault(typeof(THint)) switch {
null => Array.Empty<THint>(),
THint hint => new[] { hint },
var list => ((List<Hint>) list).Cast<THint>().ToArray()
};

/// <summary>
/// Determines whether there are any hints associated with the specified.
Expand All @@ -175,29 +143,10 @@ public THint[] GetHints<THint>(Node node)
/// <see langword="true"/> if the specified node has associated hints;
/// otherwise, <see langword="false"/>.
/// </returns>
public bool HasHints(Node node)
{
ArgumentValidator.EnsureArgumentNotNull(node, "node");
public bool HasHints(Node node) => GetNodeHints(node).Count > 0;

if (!hintMap.ContainsKey(node))
hintMap.Add(node, new Dictionary<Type, object>());
var nodeHintMap = hintMap.GetValueOrDefault(node);
if (nodeHintMap==null)
return false;

return nodeHintMap.Values.Count > 0;
}

public bool HasHints<THint>(Node node)
where THint : Hint
{
ArgumentValidator.EnsureArgumentNotNull(node, "node");

if (!hintMap.TryGetValue(node, out var nodeHintMap)) {
hintMap.Add(node, nodeHintMap = new Dictionary<Type, object>());
}
return nodeHintMap.ContainsKey(typeof(THint));
}
public bool HasHints<THint>(Node node) where THint : Hint =>
GetNodeHints(node).ContainsKey(typeof(THint));

#region IEnumerable<...> methods

Expand All @@ -215,6 +164,16 @@ IEnumerator IEnumerable.GetEnumerator()

#endregion

private Dictionary<Type, object> GetNodeHints(Node node)
{
ArgumentValidator.EnsureArgumentNotNull(node, "node");

if (!hintMap.TryGetValue(node, out var nodeHintMap)) {
hintMap.Add(node, nodeHintMap = new Dictionary<Type, object>());
}
return nodeHintMap;
}

#region ILockable methods

/// <inheritdoc/>
Expand Down
Loading