From f7d3ec31c417445c8bc35b722c1376cf20360642 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Thu, 25 Feb 2010 10:49:46 +0100 Subject: optimize appending of (empty) lists to (empty) lists if appending an empty lists, don't do anything. if appending to an empty list, just assign. this saves some needless detaches/reallocs. Reviewed-by: joao --- src/corelib/tools/qlist.h | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 02d434e..c6dd106 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -811,15 +811,22 @@ Q_OUTOFLINE_TEMPLATE typename QList::iterator QList::erase(typename QList< template Q_OUTOFLINE_TEMPLATE QList &QList::operator+=(const QList &l) { - Node *n = (d->ref != 1) - ? detach_helper_grow(INT_MAX, l.size()) - : reinterpret_cast(p.append2(l.p)); - QT_TRY{ - node_copy(n, reinterpret_cast(p.end()), reinterpret_cast(l.p.begin())); - } QT_CATCH(...) { - // restore the old end - d->end -= int(reinterpret_cast(p.end()) - n); - QT_RETHROW; + if (!l.isEmpty()) { + if (isEmpty()) { + *this = l; + } else { + Node *n = (d->ref != 1) + ? detach_helper_grow(INT_MAX, l.size()) + : reinterpret_cast(p.append2(l.p)); + QT_TRY { + node_copy(n, reinterpret_cast(p.end()), + reinterpret_cast(l.p.begin())); + } QT_CATCH(...) { + // restore the old end + d->end -= int(reinterpret_cast(p.end()) - n); + QT_RETHROW; + } + } } return *this; } -- cgit v0.12