[apps/shared/expression_model_store] Simplify recordSatisfyingTestAtIndex and numberOfModelsSatisfyingTest

This commit is contained in:
Ruben Dashyan
2019-09-10 09:53:32 +02:00
committed by LeaNumworks
parent 71e0c5a556
commit 526aa7ed48

View File

@@ -43,13 +43,15 @@ void ExpressionModelStore::tidy() {
int ExpressionModelStore::numberOfModelsSatisfyingTest(ModelTest test) const {
int result = 0;
int i = 0;
ExpressionModelHandle * m = privateModelForRecord(recordAtIndex(i++));
while (!m->isNull()) {
do {
ExpressionModelHandle * m = privateModelForRecord(recordAtIndex(i++));
if (m->isNull()) {
break;
}
if (test(m)) {
result++;
}
m = privateModelForRecord(recordAtIndex(i++));
}
} while (true);
return result;
}
@@ -57,18 +59,19 @@ Ion::Storage::Record ExpressionModelStore::recordSatisfyingTestAtIndex(int i, Mo
assert(0 <= i && i < numberOfModelsSatisfyingTest(test));
int index = 0;
int currentModelIndex = 0;
Ion::Storage::Record r = recordAtIndex(currentModelIndex++);
ExpressionModelHandle * m = privateModelForRecord(r);
while (!m->isNull()) {
do {
Ion::Storage::Record r = recordAtIndex(currentModelIndex++);
ExpressionModelHandle * m = privateModelForRecord(r);
if (m->isNull()) {
break;
}
if (test(m)) {
if (i == index) {
return r;
}
index++;
}
r = recordAtIndex(currentModelIndex++);
m = privateModelForRecord(r);
}
} while (true);
assert(false);
return Ion::Storage::Record();
}