summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@nokia.com>2010-02-25 09:49:46 (GMT)
committerOswald Buddenhagen <oswald.buddenhagen@nokia.com>2010-02-25 09:53:37 (GMT)
commitf7d3ec31c417445c8bc35b722c1376cf20360642 (patch)
tree8235a4ee02dfa6f5a5852855af9d7781ea069e5d /src/corelib/tools
parent3b699af494d7e9827b9eb26658b8cb4cb3e84dab (diff)
downloadQt-f7d3ec31c417445c8bc35b722c1376cf20360642.zip
Qt-f7d3ec31c417445c8bc35b722c1376cf20360642.tar.gz
Qt-f7d3ec31c417445c8bc35b722c1376cf20360642.tar.bz2
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
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qlist.h25
1 files 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<T>::iterator QList<T>::erase(typename QList<
template <typename T>
Q_OUTOFLINE_TEMPLATE QList<T> &QList<T>::operator+=(const QList<T> &l)
{
- Node *n = (d->ref != 1)
- ? detach_helper_grow(INT_MAX, l.size())
- : reinterpret_cast<Node *>(p.append2(l.p));
- QT_TRY{
- node_copy(n, reinterpret_cast<Node *>(p.end()), reinterpret_cast<Node *>(l.p.begin()));
- } QT_CATCH(...) {
- // restore the old end
- d->end -= int(reinterpret_cast<Node *>(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<Node *>(p.append2(l.p));
+ QT_TRY {
+ node_copy(n, reinterpret_cast<Node *>(p.end()),
+ reinterpret_cast<Node *>(l.p.begin()));
+ } QT_CATCH(...) {
+ // restore the old end
+ d->end -= int(reinterpret_cast<Node *>(p.end()) - n);
+ QT_RETHROW;
+ }
+ }
}
return *this;
}