From 5dfd1355954619fce7e2f90dbe89e1fd104f653b Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 1 Oct 2017 03:25:33 +0200 Subject: [PATCH] Library: remove redundant checks from IterAdapter implementation Explicitly assuming that those functions are called solely from IterAdapter and that they are implemented in a typical standard style, we're able to elide two redundant calls to the checkPoint() function. Since checkPoint typically performs some non-trivial checks, this has the potential of a significant performance improvement - we check (and throw ITER_EXHAUST) anyway from operator++, so we know that pos is valid - the iterate() function ensures checkPoint is invoked right after iterNext, and thus the typical standard implementation of iterNext need not do the same --- src/lib/diff/record.hpp | 3 +-- src/lib/iter-adapter.hpp | 3 +-- src/lib/iter-source.hpp | 2 +- src/lib/path-array.hpp | 3 +-- tests/library/iter-adapter-test.cpp | 10 +++++++--- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/lib/diff/record.hpp b/src/lib/diff/record.hpp index 638648c8b..3cf404976 100644 --- a/src/lib/diff/record.hpp +++ b/src/lib/diff/record.hpp @@ -312,10 +312,9 @@ namespace diff{ /** Implementation of Iteration-logic: pull next element. */ friend void - iterNext (const Record* src, ElmIter& pos) + iterNext (const Record*, ElmIter& pos) { ++pos; - checkPoint (src,pos); } /** Implementation of Iteration-logic: detect iteration end. diff --git a/src/lib/iter-adapter.hpp b/src/lib/iter-adapter.hpp index 0575f8fb7..1cba5301b 100644 --- a/src/lib/iter-adapter.hpp +++ b/src/lib/iter-adapter.hpp @@ -238,8 +238,7 @@ namespace lib { void iterate() { - if (check()) - iterNext (source_,pos_); // extension point: free function iterNext(...) + iterNext (source_,pos_); // extension point: free function iterNext(...) check(); } // checkPoint() might mark end condition // for comparison with IterAdapter{} diff --git a/src/lib/iter-source.hpp b/src/lib/iter-source.hpp index 28d02d29e..d25beb0a9 100644 --- a/src/lib/iter-source.hpp +++ b/src/lib/iter-source.hpp @@ -96,7 +96,7 @@ namespace lib { virtual Pos firstResult () =0; /** iteration step: switch on to the next element. - * The pos pointer may be set to NULL to report + * The pos pointer should be set to NULL to report * iteration end */ virtual void nextResult(Pos& pos) =0; diff --git a/src/lib/path-array.hpp b/src/lib/path-array.hpp index 6b51cf484..413d59b89 100644 --- a/src/lib/path-array.hpp +++ b/src/lib/path-array.hpp @@ -311,10 +311,9 @@ namespace lib { /** Implementation of Iteration-logic: pull next element. */ friend void - iterNext (const PathArray* src, const Literal*& pos) + iterNext (const PathArray*, const Literal*& pos) { ++pos; - checkPoint (src,pos); } /** Implementation of Iteration-logic: detect iteration end. */ diff --git a/tests/library/iter-adapter-test.cpp b/tests/library/iter-adapter-test.cpp index d783a7da0..4cd232fdf 100644 --- a/tests/library/iter-adapter-test.cpp +++ b/tests/library/iter-adapter-test.cpp @@ -135,13 +135,17 @@ namespace test{ protected: /* ==== API for the IterAdapter ==== */ - /** Implementation of Iteration-logic: pull next element. */ + /** Implementation of Iteration-logic: pull next element. + * @remarks typically the implementation is simplistic, + * since the way this extension point is called from IterAdapter + * ensures that _`pos` is still valid_ and that the `checkPoint()` function + * is invoked immediately afterwards, allowing to adjust `pos` if necessary + */ template friend void - iterNext (const TestContainer* src, ITER& pos) + iterNext (const TestContainer*, ITER& pos) { ++pos; - checkPoint (src,pos); } /** Implementation of Iteration-logic: detect iteration end.