summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2015-06-15 15:34:56 -0700
committerThiago Macieira <thiago.macieira@intel.com>2015-08-10 03:41:41 +0000
commitd9d9420d8d637064b9a5cc25ea91d96767b31a85 (patch)
treef9427e9675cdf40a61a22fa32f1a5d4b605f1a26 /src/corelib
parentdafa3618d232a611108dcd511e9e7af1aabd361e (diff)
Add a dedicated QListData::realloc_grow for growing QList
This hides the call to ::grow to now two places in the source code, so it will be easier to fix the inefficient call to qAllocMore. Change-Id: I5d1e6f7607404caa96e4ffff13e80a3e4cb0ee93 Reviewed-by: Ulf Hermann <ulf.hermann@theqtcompany.com> Reviewed-by: Alex Trotsenko <alex1973tr@gmail.com>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/tools/qlist.cpp18
-rw-r--r--src/corelib/tools/qlist.h1
2 files changed, 16 insertions, 3 deletions
diff --git a/src/corelib/tools/qlist.cpp b/src/corelib/tools/qlist.cpp
index 2e4ecbf5c9..509afadfc2 100644
--- a/src/corelib/tools/qlist.cpp
+++ b/src/corelib/tools/qlist.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
+** Copyright (C) 2015 Intel Corporation.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -148,6 +149,17 @@ void QListData::realloc(int alloc)
d->begin = d->end = 0;
}
+void QListData::realloc_grow(int growth)
+{
+ Q_ASSERT(!d->ref.isShared());
+ int alloc = grow(d->alloc + growth);
+ Data *x = static_cast<Data *>(::realloc(d, DataHeaderSize + alloc * sizeof(void *)));
+ Q_CHECK_PTR(x);
+
+ d = x;
+ d->alloc = alloc;
+}
+
void QListData::dispose(Data *d)
{
Q_ASSERT(!d->ref.isShared());
@@ -167,7 +179,7 @@ void **QListData::append(int n)
::memcpy(d->array, d->array + b, e * sizeof(void *));
d->begin = 0;
} else {
- realloc(grow(d->alloc + n));
+ realloc_grow(n);
}
}
d->end = e + n;
@@ -191,7 +203,7 @@ void **QListData::prepend()
Q_ASSERT(!d->ref.isShared());
if (d->begin == 0) {
if (d->end >= d->alloc / 3)
- realloc(grow(d->alloc + 1));
+ realloc_grow(1);
if (d->end < d->alloc / 3)
d->begin = d->alloc - 2 * d->end;
@@ -218,7 +230,7 @@ void **QListData::insert(int i)
if (d->begin == 0) {
if (d->end == d->alloc) {
// If the array is full, we expand it and move some items rightward
- realloc(grow(d->alloc + 1));
+ realloc_grow(1);
} else {
// If there is free space at the end of the array, we move some items rightward
}
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h
index e1804e17e5..32e0141d55 100644
--- a/src/corelib/tools/qlist.h
+++ b/src/corelib/tools/qlist.h
@@ -90,6 +90,7 @@ struct Q_CORE_EXPORT QListData {
Data *detach(int alloc);
Data *detach_grow(int *i, int n);
void realloc(int alloc);
+ void realloc_grow(int growth);
inline void dispose() { dispose(d); }
static void dispose(Data *d);
static const Data shared_null;