~adamreichold/qpdfview/trunk

« back to all changes in this revision

Viewing changes to sources/searchmodel.cpp

  • Committer: Adam Reichold
  • Date: 2017-04-19 21:01:25 UTC
  • mto: This revision was merged to the branch mainline in revision 2043.
  • Revision ID: adam.reichold@t-online.de-20170419210125-x3ubrcjkdmjzkn5g
Fix usage of QList in the bookmark and search models and various small performance issues reported by the clazy tool using the checks of "level0,level1,level2,no-missing-qobject-macro,no-qstring-allocations,no-copyable-polymorphic,no-ctor-missing-parent-argument,no-reserve-candidates".

Show diffs side-by-side

added added

removed removed

Lines of Context:
323
323
 
324
324
void SearchModel::clearResults(DocumentView* view)
325
325
{
326
 
    foreach(const TextCacheKey& key, m_textWatchers.keys())
 
326
    typedef QHash< TextCacheKey, TextWatcher* >::iterator WatcherIterator;
 
327
 
 
328
    for(WatcherIterator iterator = m_textWatchers.begin(); iterator != m_textWatchers.end(); ++iterator)
327
329
    {
 
330
        const TextCacheKey& key = iterator.key();
 
331
 
328
332
        if(key.first == view)
329
333
        {
330
 
            TextWatcher* watcher = m_textWatchers.take(key);
331
 
 
 
334
            TextWatcher* const watcher = iterator.value();
332
335
            watcher->cancel();
333
336
            watcher->waitForFinished();
334
337
            watcher->deleteLater();
 
338
 
 
339
            iterator = m_textWatchers.erase(iterator);
 
340
            continue;
335
341
        }
336
342
    }
337
343
 
343
349
        }
344
350
    }
345
351
 
346
 
    const QList< DocumentView* >::iterator at = qBinaryFind(m_views.begin(), m_views.end(), view);
 
352
    const QVector< DocumentView* >::iterator at = qBinaryFind(m_views.begin(), m_views.end(), view);
347
353
    const int row = at - m_views.begin();
348
354
 
349
355
    if(at == m_views.end())
408
414
 
409
415
QModelIndex SearchModel::findView(DocumentView *view) const
410
416
{
411
 
    const QList< DocumentView* >::const_iterator at = qBinaryFind(m_views.constBegin(), m_views.constEnd(), view);
 
417
    const QVector< DocumentView* >::const_iterator at = qBinaryFind(m_views.constBegin(), m_views.constEnd(), view);
412
418
    const int row = at - m_views.constBegin();
413
419
 
414
420
    if(at == m_views.constEnd())
421
427
 
422
428
QModelIndex SearchModel::findOrInsertView(DocumentView* view)
423
429
{
424
 
    QList< DocumentView* >::iterator at = qBinaryFind(m_views.begin(), m_views.end(), view);
425
 
    int row = at - m_views.begin();
 
430
    const QVector< DocumentView* >::iterator at = qLowerBound(m_views.begin(), m_views.end(), view);
 
431
    const int row = at - m_views.begin();
426
432
 
427
 
    if(at == m_views.end())
 
433
    if(at == m_views.end() || *at != view)
428
434
    {
429
 
        at = qUpperBound(m_views.begin(), m_views.end(), view);
430
 
        row = at - m_views.begin();
431
 
 
432
435
        beginInsertRows(QModelIndex(), row, row);
433
436
 
434
437
        m_views.insert(at, view);