[KPhotoAlbum] Inefficiency in ImageSearchInfo::match()

Johannes Zarl isilmendil at gmx.net
Tue Sep 11 12:58:21 BST 2012


On Tuesday 11 September 2012 12:53:57 Jesper K. Pedersen wrote:
> On Sunday 09 September 2012 20:07:34 Robert Krawitz wrote:
> > Is there any reason it does this rather than simply return if any of
> > these tests fail?
> 
> I'm 99% sure that &= will not evaluate the right side if the left side
> already is false.

C++ actually has to evaluate the right side of the code. The arguments of the 
operator&= are evaluated before operator&= is called.

Short example:

cat > test.cpp <<EOF
#include <iostream>

bool trueFunction()
{
    std::cout << "trueFunction called." <<std::endl;                                                                                                                                                                                     
    return true;                                                                                                                                                                                                                         
}                                                                                                                                                                                                                                            
                                                                                                                                                                                                                                             
int main() {                                                                                                                                                                                                                                 
    bool b= false;                                                                                                                                                                                                                       
    b &= trueFunction();                                                                                                                                                                                                                 
    std::cout << "b is: " << ( b ? "true" : "false" ) << std::endl;                                                                                                                                                                      
    return 0;                                                                                                                                                                                                                            
}
EOF

g++ -o test test.cpp
./test
trueFunction called.
b is: false

Cheers,
  Johannes



More information about the Kphotoalbum mailing list