[KPhotoAlbum] Inefficiency in ImageSearchInfo::match()
Robert Krawitz
rlk at alum.mit.edu
Tue Sep 11 13:48:41 BST 2012
On Tue, 11 Sep 2012 14:26:21 +0200, Jesper K. Pedersen wrote:
> Ahh x &= y is equal to x = x & y NOT x = x && y;
>
> That can be fixed with rewriting the code to
>
> b = b && trueFunction()
>
> and in the KPA code doing similar. Robert feel free to fix.
I'd still rather have it explicitly short-circuit, but at least this
would be better.
> On Tuesday 11 September 2012 13:58:21 Johannes Zarl wrote:
>> 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
--
Robert Krawitz <rlk at alum.mit.edu>
MIT VI-3 1987 - Congratulations MIT Engineers men's hoops Final Four!
Tall Clubs International -- http://www.tall.org/ or 1-888-IM-TALL-2
Member of the League for Programming Freedom -- http://ProgFree.org
Project lead for Gutenprint -- http://gimp-print.sourceforge.net
"Linux doesn't dictate how I work, I dictate how Linux works."
--Eric Crampton
More information about the Kphotoalbum
mailing list