Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 2 additions & 5 deletions Orm/Xtensive.Orm/Collections/FlagCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,12 @@ bool ICollection<KeyValuePair<TKey, TFlag>>.Contains(KeyValuePair<TKey, TFlag> i
/// <inheritdoc/>
public IEnumerator<KeyValuePair<TKey, TFlag>> GetEnumerator()
{
for (int i = 0; i < keys.Count; i++)
for (int i = 0, count = keys.Count; i < count; i++)
yield return new KeyValuePair<TKey, TFlag>(keys[i], Converter.ConvertBackward(flags[1 << i]));
}

/// <inheritdoc/>
IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable<KeyValuePair<TKey, TFlag>>)this).GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

#endregion

Expand Down
16 changes: 13 additions & 3 deletions Orm/Xtensive.Orm/Orm/Rse/RecordSetHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// Created by: Alexey Kochetov
// Created: 2007.09.13

using System.Buffers;
using Xtensive.Collections;
using Xtensive.Core;
using Xtensive.Orm.Model;
Expand All @@ -20,6 +19,8 @@ namespace Xtensive.Orm.Rse
[Serializable]
public sealed class RecordSetHeader
{
private static readonly DirectionCollection<ColNum> EmptyOrder = new();

private TupleDescriptor orderTupleDescriptor;

/// <summary>
Expand Down Expand Up @@ -344,8 +345,17 @@ public RecordSetHeader(

ColumnGroups = columnGroups ?? [];
orderTupleDescriptor = orderKeyDescriptor ?? TupleDescriptor.Empty;
Order = order ?? new DirectionCollection<ColNum>();
Order.Lock(true);
if (order != null) {
(Order = order).Lock();
}
else {
Order = EmptyOrder;
}
}

static RecordSetHeader()
Copy link

@snaumenko-st snaumenko-st Feb 12, 2025

Choose a reason for hiding this comment

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

Is there a way to get rid of this static .ctor and create an empty locked object instantly?
static .ctor has more performance penalties than initializer.

Copy link
Collaborator Author

@SergeiPavlov SergeiPavlov Feb 12, 2025

Choose a reason for hiding this comment

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

It is one-time per process penalty, right?
DO has plenty of static constructors.

Of course we can add yet one DirectionCollection constructor just for this purpose

Choose a reason for hiding this comment

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

I can't remember exactly where I read it. It's not a major problem, I believe, but initializers need less checks on type load.
I'll try to figure out more info on this someday :)

{
EmptyOrder.Lock();
}
}
}