Skip to content

Commit a5ff3f6

Browse files
committed
Returns results as expected
1 parent 866386d commit a5ff3f6

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

Orm/Xtensive.Orm/Sorting/TopologicalSorter.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,13 @@ public static IReadOnlyList<TNodeItem> SortToList<TNodeItem>(
183183
/// In this case <paramref name="nodes"/> will contain only the loop edges.</returns>
184184
public static IEnumerable<TNodeItem> Sort<TNodeItem, TConnectionItem>(
185185
List<Node<TNodeItem, TConnectionItem>> nodes,
186-
out List<Node<TNodeItem, TConnectionItem>> loops) => SortInternal(nodes, out loops).sorted ?? Array.Empty<TNodeItem>();
186+
out List<Node<TNodeItem, TConnectionItem>> loops)
187+
{
188+
var (sorted, count) = SortInternal(nodes, out loops) /* ?? Array.Empty<TNodeItem>()*/;
189+
return (sorted is not null && count == 0)
190+
? Array.Empty<TNodeItem>()
191+
: sorted;
192+
}
187193

188194
/// <summary>
189195
/// Sorts the specified oriented graph of the nodes in their topological order
@@ -199,9 +205,11 @@ public static IReadOnlyList<TNodeItem> SortToList<TNodeItem, TConnectionItem>(
199205
out List<Node<TNodeItem, TConnectionItem>> loops)
200206
{
201207
var (sorted, count) = SortInternal(nodes, out loops);
202-
return (sorted is null || count == 0)
203-
? Array.Empty<TNodeItem>()
204-
: sorted.ToArray(count);
208+
return (sorted is null)
209+
? null
210+
: count == 0
211+
? Array.Empty<TNodeItem>()
212+
: sorted.ToArray(count);
205213
}
206214

207215
/// <summary>

0 commit comments

Comments
 (0)