Skip to content

Commit 9c5de93

Browse files
committed
Skipping definition of enumerable mapping loop continue label where possible
1 parent 7b1abb8 commit 9c5de93

File tree

6 files changed

+16
-2
lines changed

6 files changed

+16
-2
lines changed

AgileMapper/ObjectPopulation/Enumerables/Dictionaries/DictionaryPopulationBuilder.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ private Expression AssignDictionaryEntryFromKeyValuePair(
8989

9090
private Expression AssignDictionaryEntry(IPopulationLoopData loopData, IObjectMappingData mappingData)
9191
{
92+
loopData.NeedsContinueTarget = true;
93+
9294
var dictionaryEntryMember = _targetDictionaryMember.GetElementMember();
9395

9496
return AssignDictionaryEntry(loopData, dictionaryEntryMember, mappingData);

AgileMapper/ObjectPopulation/Enumerables/EnumerableSourcePopulationLoopData.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public EnumerableSourcePopulationLoopData(
3939

4040
public EnumerablePopulationBuilder Builder { get; }
4141

42+
public bool NeedsContinueTarget { get; set; }
43+
4244
public LabelTarget ContinueLoopTarget { get; }
4345

4446
public Expression LoopExitCheck { get; }

AgileMapper/ObjectPopulation/Enumerables/IPopulationLoopData.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
internal interface IPopulationLoopData
88
{
9+
bool NeedsContinueTarget { get; set; }
10+
911
LabelTarget ContinueLoopTarget { get; }
1012

1113
Expression LoopExitCheck { get; }
@@ -36,7 +38,10 @@ public static Expression BuildPopulationLoop<TLoopData>(
3638
elementPopulation,
3739
Expression.PreIncrementAssign(builder.Counter));
3840

39-
var populationLoop = Expression.Loop(loopBody, breakLoop.Target, loopData.ContinueLoopTarget);
41+
var populationLoop = loopData.NeedsContinueTarget
42+
? Expression.Loop(loopBody, breakLoop.Target, loopData.ContinueLoopTarget)
43+
: Expression.Loop(loopBody, breakLoop.Target);
44+
4045
var adaptedLoop = loopData.Adapt(populationLoop);
4146

4247
var population = Expression.Block(

AgileMapper/ObjectPopulation/Enumerables/IndexedSourcePopulationLoopData.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public IndexedSourcePopulationLoopData(EnumerablePopulationBuilder builder)
2828
: builder.Context.GetSourceParameterFor(builder.SourceTypeHelper.ElementType);
2929
}
3030

31+
public bool NeedsContinueTarget { get; set; }
32+
3133
public LabelTarget ContinueLoopTarget { get; }
3234

3335
public Expression LoopExitCheck { get; }

AgileMapper/ObjectPopulation/Enumerables/SourceElementsDictionaryPopulationLoopData.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ private Expression GetContainsElementKeyCheck()
113113
private Expression GetNoKeysWithMatchingStartQuery()
114114
=> _dictionaryVariables.GetNoKeysWithMatchingStartQuery(_targetElementKey);
115115

116+
public bool NeedsContinueTarget { get; set; }
117+
116118
public LabelTarget ContinueLoopTarget { get; }
117119

118120
public Expression LoopExitCheck { get; }

AgileMapper/ObjectPopulation/Enumerables/SourceObjectDictionaryPopulationLoopData.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
namespace AgileObjects.AgileMapper.ObjectPopulation.Enumerables
22
{
3-
using System.Linq;
43
using System.Linq.Expressions;
54
using DataSources;
65
using Extensions;
@@ -41,6 +40,8 @@ private Expression GetCompositeLoopExitCheck()
4140
return Expression.Block(ifEnumeratorReturnResult, returnElementsResult);
4241
}
4342

43+
public bool NeedsContinueTarget { get; set; }
44+
4445
public LabelTarget ContinueLoopTarget { get; }
4546

4647
public Expression LoopExitCheck { get; }

0 commit comments

Comments
 (0)