[KPhotoAlbum] Inefficiency in ImageSearchInfo::match()
Robert Krawitz
rlk at alum.mit.edu
Tue Sep 11 13:15:27 BST 2012
On Tue, 11 Sep 2012 12:53:57 +0200, Jesper K. Pedersen wrote:
> On Sunday 09 September 2012 20:07:34 Robert Krawitz wrote:
>> While coding up the file name match, I noticed that
>> ImageSearchInfo::match() doesn't return as soon as it knows that an
>> image hasn't matched. There's a lot of code of the form:
>>
>> bool ok = true;
>> #ifdef HAVE_EXIV2
>> ok = _exifSearchInfo.matches( info->fileName() );
>> #endif
>> ...
>> ok &= ( _label.isEmpty() || info->label().indexOf(_label) != -1 );
>> ...
>> return ok;
>>
>>
>> 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.
>
> So in effect it does the return right away.
Depends upon just how good the optimizer is. For example:
if ( !_date.start().isNull() ) {
// Date
// the search date matches the actual date if:
// actual.start <= search.start <= actuel.end or
// actual.start <= search.end <=actuel.end or
// search.start <= actual.start and actual.end <= search.end
bool b1 =( actualStart <= _date.start() && _date.start() <= actualEnd );
bool b2 =( actualStart <= _date.end() && _date.end() <= actualEnd );
bool b3 = ( _date.start() <= actualStart && ( actualEnd <= _date.end() || _date.end().isNull() ) );
ok &= ( ( b1 || b2 || b3 ) );
} else if ( !_date.end().isNull() ) {
bool b1 = ( actualStart <= _date.end() && _date.end() <= actualEnd );
bool b2 = ( actualEnd <= _date.end() );
ok &= ( ( b1 || b2 ) );
}
it would have to look rather deeply at the expressions. And:
And:
QString txt = info->description();
if ( !_description.isEmpty() ) {
QStringList list = _description.split(QChar::fromLatin1(' '), QString::SkipEmptyParts);
for( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
ok &= ( txt.indexOf( *it, 0, Qt::CaseInsensitive ) != -1 );
}
}
--
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