Skip to content

Commit ee5b800

Browse files
Fix: Added empty refs collection check in Cell constructor
Before: When calculating the maximum level using refs.Max(x => x.Level), an exception "Sequence contains no elements" occurred if the collection was empty. After: Added a check for non-empty collection using refs.Count > 0 (instead of refs.Any()) and defaulted the level to (byte)0 if the collection is empty. This aligns with CA1860 recommendations and improves performance.
1 parent 84072f1 commit ee5b800

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

TonLibDotNet/Cells/Cell.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ public class Cell
99
public const int MaxBitsCount = 1023;
1010
public const int MaxRefs = 4;
1111

12-
public Cell(ReadOnlySpan<byte> content, bool isAugmented, ICollection<Cell>? refs = null)
13-
: this(false, refs != null && refs.Any() ? refs.Max(x => x.Level) : (byte)0, content, isAugmented, refs)
14-
{
15-
// Nothing.
16-
}
12+
public Cell(ReadOnlySpan<byte> content, bool isAugmented, ICollection<Cell>? refs = null)
13+
: this(false, refs != null && refs.Count > 0 ? refs.Max(x => x.Level) : (byte)0, content, isAugmented, refs)
14+
{
15+
// Nothing.
16+
}
17+
1718

18-
public Cell(bool isExotic, byte level, ReadOnlySpan<byte> content, bool isAugmented, ICollection<Cell>? refs = null)
19+
public Cell(bool isExotic, byte level, ReadOnlySpan<byte> content, bool isAugmented, ICollection<Cell>? refs = null)
1920
{
2021
if (content.Length > MaxContentLength)
2122
{

0 commit comments

Comments
 (0)