Skip to content
Merged
5 changes: 1 addition & 4 deletions Orm/Xtensive.Orm.Oracle/Sql.Drivers.Oracle/v09/Translator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ namespace Xtensive.Sql.Drivers.Oracle.v09
{
internal class Translator : SqlTranslator
{
/// <inheritdoc/>
public override string NewLine => "\n";

/// <inheritdoc/>
public override string BatchBegin => "BEGIN\n";

Expand Down Expand Up @@ -441,4 +438,4 @@ public Translator(SqlDriver driver)
{
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected virtual bool IsAcceptable(in TypeRegistration registration, Type type)
return type.IsSubclassOf(BaseType) && (ns.IsNullOrEmpty() || (type.FullName.IndexOf(ns + ".", StringComparison.InvariantCulture) >= 0));
}

private static IList<Type> FindTypes(Assembly assembly, Type baseType, TypeFilter filter)
private static IReadOnlyList<Type> FindTypes(Assembly assembly, Type baseType, TypeFilter filter)
{
ArgumentNullException.ThrowIfNull(assembly);
ArgumentNullException.ThrowIfNull(baseType);
Expand Down
12 changes: 4 additions & 8 deletions Orm/Xtensive.Orm/Collections/TypeRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
// Created by: Dmitri Maximov
// Created: 2007.08.03

using System;
using System.Collections;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Linq;
using Xtensive.Core;
using Xtensive.IoC;

Expand All @@ -28,7 +25,7 @@ public class TypeRegistry : LockableBase,
private readonly List<Type> types = new List<Type>();
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private ISet<Type> typeSet = new HashSet<Type>();
private readonly List<TypeRegistration> actions = new List<TypeRegistration>();
private List<TypeRegistration> actions = new List<TypeRegistration>();
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly HashSet<TypeRegistration> actionSet = new HashSet<TypeRegistration>();
private readonly ITypeRegistrationProcessor processor;
Expand Down Expand Up @@ -110,9 +107,8 @@ public void Register(Assembly assembly, string @namespace)
public bool Register(in TypeRegistration action)
{
EnsureNotLocked();
if (actionSet.Contains(action))
if (!actionSet.Add(action))
return false;
actionSet.Add(action);
actions.Add(action);
return true;
}
Expand All @@ -126,8 +122,8 @@ private void ProcessPendingActions()
isProcessingPendingActions = true;
try {
while (true) {
var oldActions = actions.ToList();
actions.Clear();
var oldActions = actions;
actions = new();
foreach (var action in oldActions)
processor.Process(this, action);
if (actions.Count == 0)
Expand Down
60 changes: 0 additions & 60 deletions Orm/Xtensive.Orm/Conversion/ConvertingEnumerable.cs

This file was deleted.

84 changes: 0 additions & 84 deletions Orm/Xtensive.Orm/Conversion/Internals/ConvertingEnumerator.cs

This file was deleted.

59 changes: 23 additions & 36 deletions Orm/Xtensive.Orm/Core/LockableBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,37 @@
// Created by: Alex Yakunin
// Created: 2007.11.22

using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;

namespace Xtensive.Core;

namespace Xtensive.Core
/// <summary>
/// Base class for <see cref="ILockable"/> implementors.
/// </summary>
[Serializable]
public abstract class LockableBase(bool isLocked = false) : ILockable
{
/// <inheritdoc/>
public bool IsLocked { [DebuggerStepThrough] get; private set; } = isLocked;

[MethodImpl(MethodImplOptions.NoInlining)]
private static void ThrowInstanceIsLockedException() => throw new InstanceIsLockedException(Strings.ExInstanceIsLocked);

/// <summary>
/// Base class for <see cref="ILockable"/> implementors.
/// Ensures the object is not locked (see <see cref="ILockable.Lock()"/>) yet.
/// </summary>
[Serializable]
public abstract class LockableBase: ILockable
/// <exception cref="InstanceIsLockedException">The instance is locked.</exception>
public void EnsureNotLocked()
{

/// <inheritdoc/>
public bool IsLocked { [DebuggerStepThrough] get; private set; }

/// <summary>
/// Ensures the object is not locked (see <see cref="ILockable.Lock()"/>) yet.
/// </summary>
/// <exception cref="InstanceIsLockedException">The instance is locked.</exception>
public void EnsureNotLocked()
{
if (IsLocked) {
throw new InstanceIsLockedException(Strings.ExInstanceIsLocked);
}
if (IsLocked) {
ThrowInstanceIsLockedException();
Comment on lines +28 to +31

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't look like necessary change. The method is small enough and encapsulates Exception throwing inside. Most probably there is no sense of splitting it into 2 even smaller.

Copy link
Collaborator Author

@SergeiPavlov SergeiPavlov Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any throw code is big actually
MS also uses this ThrowHelper pattern over dotnet codebase
See https://dunnhq.com/posts/2022/throw-helper/

}
}

/// <inheritdoc/>
public void Lock() => Lock(true);

/// <inheritdoc/>
public virtual void Lock(bool recursive) => IsLocked = true;



// Constructors
/// <inheritdoc/>
public void Lock() => Lock(true);

/// <summary>
/// Initializes new instance of this type.
/// </summary>
/// <param name="isLocked">Initial <see cref="IsLocked"/> property value.</param>
protected LockableBase(bool isLocked = false)
{
IsLocked = isLocked;
}
}
/// <inheritdoc/>
public virtual void Lock(bool recursive) => IsLocked = true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private void BuildClassTableIndexes(TypeInfo type)
if (untypedIndexes.Contains(primaryIndex) && primaryIndex.ReflectedType == root) {
primaryIndex = type.Indexes.Single(i => i.DeclaringIndex == primaryIndex.DeclaringIndex && i.IsTyped);
}
var filterByTypes = type.AllDescendants.Append(type).ToList();
var filterByTypes = type.AllDescendants.Append(type).ToArray();

// Build virtual primary index
if (ancestors.Count > 0) {
Expand Down
4 changes: 2 additions & 2 deletions Orm/Xtensive.Orm/Orm/Building/Builders/IndexBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ private IndexInfo BuildJoinIndex(TypeInfo reflectedType, IEnumerable<IndexInfo>
valueColumnMapping.Add((item.i, item.columns));
}

result.ValueColumnsMap = valueColumnMapping;
result.ValueColumnsMap = valueColumnMapping.ToArray();
result.ValueColumns.AddRange(GatherValueColumns(columnsToAdd));
result.Name = nameBuilder.BuildIndexName(reflectedType, result);
result.Group = BuildColumnGroup(result);
Expand Down Expand Up @@ -757,7 +757,7 @@ private IndexInfo BuildViewIndex(TypeInfo reflectedType, IndexInfo indexToApplyV
}

result.ValueColumns.AddRange(valueColumns);
result.SelectColumns = columnMap;
result.SelectColumns = columnMap.ToArray();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it better than before?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because Arrays are more lightweight than List<>
Index building is one-time operation. It is better to store the most efficient data structure

result.Name = nameBuilder.BuildIndexName(reflectedType, result);
result.Group = BuildColumnGroup(result);

Expand Down
22 changes: 13 additions & 9 deletions Orm/Xtensive.Orm/Orm/Linq/Expressions/StructureExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal sealed class StructureExpression : ParameterizedExpression, IPersistent

public IReadOnlyList<PersistentFieldExpression> Fields => fields;

private void SetFields(List<PersistentFieldExpression> value)
private void SetFields(IReadOnlyList<PersistentFieldExpression> value)
{
fields = value;
foreach (var fieldExpression in fields.OfType<FieldExpression>()) {
Expand All @@ -42,10 +42,11 @@ public override Expression Remap(ColNum offset, Dictionary<Expression, Expressio
var mapping = new Segment<ColNum>((ColNum) (Mapping.Offset + offset), Mapping.Length);
var result = new StructureExpression(PersistentType, mapping);
processedExpressions.Add(this, result);
var processedFields = new List<PersistentFieldExpression>(fields.Count);
var processedFields = new PersistentFieldExpression[fields.Count];
int i = 0;
foreach (var field in fields) {
// Do not convert to LINQ. We intentionally avoiding closure creation here
processedFields.Add(field.Remap(offset, processedExpressions));
processedFields[i++] = field.Remap(offset, processedExpressions);
}

result.SetFields(processedFields);
Expand Down Expand Up @@ -96,10 +97,11 @@ public override ParameterizedExpression BindParameter(ParameterExpression parame

var result = new StructureExpression(PersistentType, Mapping);
processedExpressions.Add(this, result);
var processedFields = new List<PersistentFieldExpression>(fields.Count);
var processedFields = new PersistentFieldExpression[fields.Count];
int i = 0;
foreach (var field in fields) {
// Do not convert to LINQ. We intentionally avoiding closure creation here
processedFields.Add((PersistentFieldExpression) field.BindParameter(parameter, processedExpressions));
processedFields[i++] = (PersistentFieldExpression) field.BindParameter(parameter, processedExpressions);
}

result.SetFields(processedFields);
Expand All @@ -114,10 +116,11 @@ public override Expression RemoveOuterParameter(Dictionary<Expression, Expressio

var result = new StructureExpression(PersistentType, Mapping);
processedExpressions.Add(this, result);
var processedFields = new List<PersistentFieldExpression>(fields.Count);
var processedFields = new PersistentFieldExpression[fields.Count];
int i = 0;
foreach (var field in fields) {
// Do not convert to LINQ. We intentionally avoiding closure creation here
processedFields.Add((PersistentFieldExpression) field.RemoveOuterParameter(processedExpressions));
processedFields[i++] = (PersistentFieldExpression) field.RemoveOuterParameter(processedExpressions);
}

result.SetFields(processedFields);
Expand All @@ -131,12 +134,13 @@ public static StructureExpression CreateLocalCollectionStructure(TypeInfo typeIn
}

var sourceFields = typeInfo.Fields;
var destinationFields = new List<PersistentFieldExpression>(sourceFields.Count);
var destinationFields = new PersistentFieldExpression[sourceFields.Count];
var result = new StructureExpression(typeInfo, mapping);
result.SetFields(destinationFields);
int i = 0;
foreach (var field in sourceFields) {
// Do not convert to LINQ. We intentionally avoiding closure creation here
destinationFields.Add(BuildNestedFieldExpression(field, mapping.Offset));
destinationFields[i++] = BuildNestedFieldExpression(field, mapping.Offset);
}

return result;
Expand Down
Loading