summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@nokia.com>2010-02-18 21:18:23 (GMT)
committerOswald Buddenhagen <oswald.buddenhagen@nokia.com>2010-02-22 17:12:16 (GMT)
commit4967231a9e5c39de3a60b61db9b6a71266a04829 (patch)
tree486e3dcf053b8399bbd15042ae23dd011ef5816f /src
parent422f353135dc8a6b3694a7f0994429df7695d4bf (diff)
downloadQt-4967231a9e5c39de3a60b61db9b6a71266a04829.zip
Qt-4967231a9e5c39de3a60b61db9b6a71266a04829.tar.gz
Qt-4967231a9e5c39de3a60b61db9b6a71266a04829.tar.bz2
optimize queue-like structures
a list to which we append after we took something from the beginning is most likely a queue, and it seems unlikely that we would suddenly start prepending to it. consequently, optimizing the prepending case by leaving the first third of the allocation free just increases the number of times the array needs to be shifted down. Reviewed-by: joao
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qlist.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/corelib/tools/qlist.cpp b/src/corelib/tools/qlist.cpp
index 1576b40..39c1beb 100644
--- a/src/corelib/tools/qlist.cpp
+++ b/src/corelib/tools/qlist.cpp
@@ -188,9 +188,9 @@ void **QListData::append()
int n = d->end - d->begin;
if (d->begin > 2 * d->alloc / 3) {
// we have enough space. Just not at the end -> move it.
- ::memcpy(d->array + n, d->array + d->begin, n * sizeof(void *));
- d->begin = n;
- d->end = n * 2;
+ ::memcpy(d->array, d->array + d->begin, n * sizeof(void *));
+ d->begin = 0;
+ d->end = n;
} else {
realloc(grow(d->alloc + 1));
}