Skip to content

Commit cb8eff3

Browse files
committed
Avoid QueueEntry type casting
1 parent 21b39ab commit cb8eff3

File tree

1 file changed

+34
-17
lines changed

1 file changed

+34
-17
lines changed

src/NHibernate/Loader/JoinWalker.cs

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -330,19 +330,7 @@ protected void ProcessJoins()
330330
while(joinQueue.Count > 0)
331331
{
332332
QueueEntry entry = joinQueue.Dequeue();
333-
334-
switch(entry)
335-
{
336-
case CollectionQueueEntry ce:
337-
WalkCollectionTree(ce.Persister, ce.Alias, ce.Path, ce.PathAlias);
338-
break;
339-
case EntityQueueEntry eqe:
340-
WalkEntityTree(eqe.Persister, eqe.Alias, eqe.Path);
341-
break;
342-
default:
343-
depth++;
344-
break;
345-
}
333+
entry.Walk(this, ref depth);
346334
}
347335
}
348336

@@ -491,7 +479,7 @@ protected virtual void WalkEntityTree(IOuterJoinLoadable persister, string alias
491479
{
492480
int n = persister.CountSubclassProperties();
493481

494-
joinQueue.Enqueue(null);
482+
joinQueue.Enqueue(NextLevelQueueEntry.Instance);
495483
for (int i = 0; i < n; i++)
496484
{
497485
IType type = persister.GetSubclassPropertyType(i);
@@ -1272,23 +1260,52 @@ protected static string GetSelectFragment(OuterJoinableAssociation join, string
12721260
return join.GetSelectFragment(entitySuffix, collectionSuffix, next);
12731261
}
12741262

1275-
protected abstract class QueueEntry { }
1263+
protected abstract class QueueEntry
1264+
{
1265+
public abstract void Walk(JoinWalker walker, ref int depth);
1266+
}
12761267

12771268
protected abstract class QueueEntry<T> : QueueEntry where T : IJoinable
12781269
{
12791270
public string Alias { get; set; }
12801271
public T Persister { get; set; }
12811272
}
12821273

1283-
protected class EntityQueueEntry<T> : QueueEntry<T> where T : IJoinable
1274+
protected abstract class EntityQueueEntry<T> : QueueEntry<T> where T : IJoinable
12841275
{
12851276
public string Path { get; set; }
12861277
}
1287-
protected class EntityQueueEntry : EntityQueueEntry<IOuterJoinLoadable> {}
1278+
1279+
protected class EntityQueueEntry : EntityQueueEntry<IOuterJoinLoadable>
1280+
{
1281+
public override void Walk(JoinWalker walker, ref int depth)
1282+
{
1283+
walker.WalkEntityTree(Persister, Alias, Path);
1284+
}
1285+
}
12881286

12891287
protected class CollectionQueueEntry : EntityQueueEntry<IQueryableCollection>
12901288
{
12911289
public string PathAlias { get; set; }
1290+
1291+
public override void Walk(JoinWalker walker, ref int depth)
1292+
{
1293+
walker.WalkCollectionTree(Persister, Alias, Path, PathAlias);
1294+
}
1295+
}
1296+
1297+
protected class NextLevelQueueEntry : QueueEntry
1298+
{
1299+
public static NextLevelQueueEntry Instance = new NextLevelQueueEntry();
1300+
1301+
private NextLevelQueueEntry()
1302+
{
1303+
}
1304+
1305+
public override void Walk(JoinWalker walker, ref int depth)
1306+
{
1307+
depth++;
1308+
}
12921309
}
12931310
}
12941311
}

0 commit comments

Comments
 (0)