1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-14 14:24:10 +02:00

Made for (var i < GetVal()) only call GetVal() once

This commit is contained in:
Brian Fiete 2021-07-16 09:06:31 -07:00
parent 70da0856a7
commit e3bdacf505
2 changed files with 15 additions and 2 deletions

View file

@ -5845,8 +5845,6 @@ void BfModule::DoForLess(BfForEachStatement* forEachStmt)
// Cond // Cond
auto valueScopeStart = ValueScopeStart(); auto valueScopeStart = ValueScopeStart();
auto localVal = mBfIRBuilder->CreateLoad(localDef->mAddr); auto localVal = mBfIRBuilder->CreateLoad(localDef->mAddr);
if ((forEachStmt->mCollectionExpression != NULL) && (!didInference))
target = CreateValueFromExpression(forEachStmt->mCollectionExpression, varType);
if (!target) if (!target)
{ {
// Soldier on // Soldier on

View file

@ -28,6 +28,13 @@ namespace Tests
} }
} }
static int sGetValCount = 0;
static int GetVal()
{
return 10 + sGetValCount++;
}
[Test] [Test]
public static void TestBasics() public static void TestBasics()
{ {
@ -57,6 +64,14 @@ namespace Tests
Test.Assert(e.mDispCount == 3); Test.Assert(e.mDispCount == 3);
TestEnumerator2(e); TestEnumerator2(e);
Test.Assert(e.mDispCount == 4); Test.Assert(e.mDispCount == 4);
int iterations = 0;
for (int i < GetVal())
{
iterations++;
}
Test.Assert(iterations == 10);
Test.Assert(sGetValCount == 1);
} }
public static void TestEnumerator1(EnumeratorTest e) public static void TestEnumerator1(EnumeratorTest e)