diff options
author | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2010-02-18 21:18:23 (GMT) |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2010-02-22 17:12:16 (GMT) |
commit | 4967231a9e5c39de3a60b61db9b6a71266a04829 (patch) | |
tree | 486e3dcf053b8399bbd15042ae23dd011ef5816f /src/corelib/tools/qlist.cpp | |
parent | 422f353135dc8a6b3694a7f0994429df7695d4bf (diff) | |
download | Qt-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/corelib/tools/qlist.cpp')
-rw-r--r-- | src/corelib/tools/qlist.cpp | 6 |
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)); } |