From 526aa7ed48378b2afa7273b695a18ef8d85efec2 Mon Sep 17 00:00:00 2001 From: Ruben Dashyan Date: Tue, 10 Sep 2019 09:53:32 +0200 Subject: [PATCH] [apps/shared/expression_model_store] Simplify recordSatisfyingTestAtIndex and numberOfModelsSatisfyingTest --- apps/shared/expression_model_store.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/apps/shared/expression_model_store.cpp b/apps/shared/expression_model_store.cpp index 031b393d3..54eccf23d 100644 --- a/apps/shared/expression_model_store.cpp +++ b/apps/shared/expression_model_store.cpp @@ -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(); }