[string_algo] first_finderF hoist empty check out of loop

In trying to get string algorithm icontains to work with spirit's file_iterator (which I still haven't been successful with) I noticed that the check for an empty search string is in side the loop. As: // Outer loop for(input_iterator_type OuterIt=Begin; OuterIt!=End; ++OuterIt) { // Sanity check if( boost::empty(m_Search) ) return result_type( End, End ); Wouldn't it be better to hoist this check out of the loop and only do it once? Thanks, Jeff

Hi, On 4. 4. 2010 21:35, Jeff Flinn wrote:
In trying to get string algorithm icontains to work with spirit's file_iterator (which I still haven't been successful with) I noticed that the check for an empty search string is in side the loop. As:
// Outer loop for(input_iterator_type OuterIt=Begin; OuterIt!=End; ++OuterIt) { // Sanity check if( boost::empty(m_Search) ) return result_type( End, End );
Wouldn't it be better to hoist this check out of the loop and only do it once?
Good point, makes sense. Regards, Pavol.
participants (2)
-
Jeff Flinn
-
Pavol Droba