Why you are thinking it cannot work?
Following the approach used for the searchContainer.setResults(results), I thought that a similar optimization can be applied.
The total is calculated in the right place (inside the if-else chain), while only the set into the searchContainer is done at the end of the chain.
The test result appear correct, unless I'm missing something
![wiki-paging](https://f.cloud.github.com/assets/1668039/668155/d8053f4a-d809-11e2-9612-ee8becefabdd.png)