mirror of
https://bitbucket.org/smil3y/katie.git
synced 2025-02-23 18:32:55 +00:00
remove unused QContiguousCache class
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
737752f597
commit
9222708c38
25 changed files with 26 additions and 1073 deletions
|
@ -493,8 +493,6 @@ katie_generate_obsolete(QChildEvent QtCore qcoreevent.h)
|
|||
katie_generate_obsolete(QClipboardEvent QtGui qevent.h)
|
||||
katie_generate_obsolete(QCloseEvent QtGui qevent.h)
|
||||
katie_generate_obsolete(QContextMenuEvent QtGui qevent.h)
|
||||
katie_generate_obsolete(QContiguousCacheData QtCore qcontiguouscache.h)
|
||||
katie_generate_obsolete(QContiguousCacheTypedData QtCore qcontiguouscache.h)
|
||||
katie_generate_obsolete(QCustomWidgetPlugin QtUiTools customwidget.h)
|
||||
katie_generate_obsolete(QCustomWidget QtUiTools customwidget.h)
|
||||
katie_generate_obsolete(QDateEdit QtGui qdatetimeedit.h)
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
# https://wiki.archlinux.org/index.php/Arch_package_guidelines
|
||||
|
||||
pkgname=katie-git
|
||||
pkgver=4.12.0.r7595.fabde51fe
|
||||
pkgver=4.12.0.r7614.655f45c94
|
||||
pkgrel=1
|
||||
pkgdesc='C++ toolkit derived from the Qt 4.8 framework'
|
||||
arch=('i486' 'i686' 'pentium4' 'x86_64' 'arm')
|
||||
|
|
|
@ -25,9 +25,6 @@ include/katie/QtCore/QCache
|
|||
include/katie/QtCore/QChar
|
||||
include/katie/QtCore/QCharRef
|
||||
include/katie/QtCore/QChildEvent
|
||||
include/katie/QtCore/QContiguousCache
|
||||
include/katie/QtCore/QContiguousCacheData
|
||||
include/katie/QtCore/QContiguousCacheTypedData
|
||||
include/katie/QtCore/QCoreApplication
|
||||
include/katie/QtCore/QDataStream
|
||||
include/katie/QtCore/QDate
|
||||
|
@ -192,7 +189,6 @@ include/katie/QtCore/qcache.h
|
|||
include/katie/QtCore/qchar.h
|
||||
include/katie/QtCore/qconfig.h
|
||||
include/katie/QtCore/qcontainerfwd.h
|
||||
include/katie/QtCore/qcontiguouscache.h
|
||||
include/katie/QtCore/qcoreapplication.h
|
||||
include/katie/QtCore/qcoreevent.h
|
||||
include/katie/QtCore/qdatastream.h
|
||||
|
|
|
@ -13,8 +13,6 @@ incmap = {
|
|||
'QByteRef': 'qbytearray.h',
|
||||
'QCharRef': 'qstring.h',
|
||||
'QChildEvent': 'qcoreevent.h',
|
||||
'QContiguousCacheData': 'qcontiguouscache.h',
|
||||
'QContiguousCacheTypedData': 'qcontiguouscache.h',
|
||||
'QDate': 'qdatetime.h',
|
||||
'QDynamicPropertyChangeEvent': 'qcoreevent.h',
|
||||
'QEvent': 'qcoreevent.h',
|
||||
|
|
|
@ -86,9 +86,6 @@ classlist = [
|
|||
"QCommonStyle",
|
||||
"QCompleter",
|
||||
"QContextMenuEvent",
|
||||
"QContiguousCache",
|
||||
"QContiguousCacheData",
|
||||
"QContiguousCacheTypedData",
|
||||
"QCoreApplication",
|
||||
"QCryptographicHash",
|
||||
"QCursor",
|
||||
|
|
|
@ -27,7 +27,6 @@ set(CORE_PUBLIC_HEADERS
|
|||
QMap
|
||||
QTextStream
|
||||
QDebug
|
||||
QContiguousCache
|
||||
QFileInfo
|
||||
QDateTime
|
||||
QThreadPool
|
||||
|
@ -198,7 +197,6 @@ set(CORE_HEADERS
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/tools/qlocale_data_p.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tools/qmap.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tools/qmargins.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tools/qcontiguouscache.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tools/qpoint.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tools/qqueue.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tools/qrect.h
|
||||
|
@ -302,7 +300,6 @@ set(CORE_SOURCES
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/tools/qpoint.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tools/qmap.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tools/qmargins.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tools/qcontiguouscache.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tools/qrect.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tools/qregexp.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tools/qshareddata.cpp
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#include <QtCore/qtextstream.h>
|
||||
#include <QtCore/qvector.h>
|
||||
#include <QtCore/qset.h>
|
||||
#include <QtCore/qcontiguouscache.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
@ -177,19 +176,6 @@ inline QDebug operator<<(QDebug debug, const QSet<T> &set)
|
|||
return operator<<(debug, set.toList());
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline QDebug operator<<(QDebug debug, const QContiguousCache<T> &cache)
|
||||
{
|
||||
debug.nospace() << "QContiguousCache(";
|
||||
for (int i = cache.firstIndex(); i <= cache.lastIndex(); ++i) {
|
||||
debug << cache[i];
|
||||
if (i != cache.lastIndex())
|
||||
debug << ", ";
|
||||
}
|
||||
debug << ')';
|
||||
return debug.space();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline QDebug operator<<(QDebug debug, const QFlags<T> &flags)
|
||||
{
|
||||
|
|
|
@ -1,436 +0,0 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2015 The Qt Company Ltd.
|
||||
** Copyright (C) 2016 Ivailo Monev
|
||||
**
|
||||
** This file is part of the QtCore module of the Katie Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** This file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qcontiguouscache.h"
|
||||
#ifdef QT_QCONTIGUOUSCACHE_DEBUG
|
||||
#include <QDebug>
|
||||
#endif
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
#ifdef QT_QCONTIGUOUSCACHE_DEBUG
|
||||
void QContiguousCacheData::dump() const
|
||||
{
|
||||
qDebug() << "capacity:" << alloc;
|
||||
qDebug() << "count:" << count;
|
||||
qDebug() << "start:" << start;
|
||||
qDebug() << "offset:" << offset;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*! \class QContiguousCache
|
||||
\brief The QContiguousCache class is a template class that provides a contiguous cache.
|
||||
\ingroup tools
|
||||
\ingroup shared
|
||||
\reentrant
|
||||
\since 4.6
|
||||
|
||||
The QContiguousCache class provides an efficient way of caching items for
|
||||
display in a user interface view. Unlike QCache, it adds a restriction
|
||||
that elements within the cache are contiguous. This has the advantage
|
||||
of matching how user interface views most commonly request data, as
|
||||
a set of rows localized around the current scrolled position. This
|
||||
restriction allows the cache to consume less memory and processor
|
||||
cycles than QCache. The QContiguousCache class also can provide
|
||||
an upper bound on memory usage via setCapacity().
|
||||
|
||||
The simplest way of using a contiguous cache is to use the append()
|
||||
and prepend().
|
||||
|
||||
\code
|
||||
MyRecord record(int row) const
|
||||
{
|
||||
Q_ASSERT(row >= 0 && row < count());
|
||||
|
||||
while(row > cache.lastIndex())
|
||||
cache.append(slowFetchRecord(cache.lastIndex()+1));
|
||||
while(row < cache.firstIndex())
|
||||
cache.prepend(slowFetchRecord(cache.firstIndex()-1));
|
||||
|
||||
return cache.at(row);
|
||||
}
|
||||
\endcode
|
||||
|
||||
If the cache is full then the item at the opposite end of the cache from
|
||||
where the new item is appended or prepended will be removed.
|
||||
|
||||
This usage can be further optimized by using the insert() function
|
||||
in the case where the requested row is a long way from the currently cached
|
||||
items. If there is a gap between where the new item is inserted and the currently
|
||||
cached items then the existing cached items are first removed to retain
|
||||
the contiguous nature of the cache. Hence it is important to take some care then
|
||||
when using insert() in order to avoid unwanted clearing of the cache.
|
||||
|
||||
The range of valid indexes for the QContiguousCache class are from
|
||||
0 to INT_MAX. Calling prepend() such that the first index would become less
|
||||
than 0 or append() such that the last index would become greater
|
||||
than INT_MAX can result in the indexes of the cache being invalid.
|
||||
When the cache indexes are invalid it is important to call
|
||||
normalizeIndexes() before calling any of containsIndex(), firstIndex(),
|
||||
lastIndex(), at() or \l{QContiguousCache::operator[]()}{operator[]()}.
|
||||
Calling these functions when the cache has invalid indexes will result in
|
||||
undefined behavior. The indexes can be checked by using areIndexesValid()
|
||||
|
||||
In most cases the indexes will not exceed 0 to INT_MAX, and
|
||||
normalizeIndexes() will not need to be used.
|
||||
|
||||
See the \l{Contiguous Cache Example}{Contiguous Cache} example.
|
||||
*/
|
||||
|
||||
/*! \fn QContiguousCache::QContiguousCache(int capacity)
|
||||
|
||||
Constructs a cache with the given \a capacity.
|
||||
|
||||
\sa setCapacity()
|
||||
*/
|
||||
|
||||
/*! \fn QContiguousCache::QContiguousCache(const QContiguousCache<T> &other)
|
||||
|
||||
Constructs a copy of \a other.
|
||||
|
||||
This operation takes \l{constant time}, because QContiguousCache is
|
||||
\l{implicitly shared}. This makes returning a QContiguousCache from a
|
||||
function very fast. If a shared instance is modified, it will be
|
||||
copied (copy-on-write), and that takes \l{linear time}.
|
||||
|
||||
\sa operator=()
|
||||
*/
|
||||
|
||||
/*! \fn QContiguousCache::~QContiguousCache()
|
||||
|
||||
Destroys the cache.
|
||||
*/
|
||||
|
||||
/*! \fn void QContiguousCache::detach()
|
||||
\internal
|
||||
*/
|
||||
|
||||
/*! \typedef QContiguousCache::value_type
|
||||
\internal
|
||||
*/
|
||||
|
||||
/*! \typedef QContiguousCache::pointer
|
||||
\internal
|
||||
*/
|
||||
|
||||
/*! \typedef QContiguousCache::const_pointer
|
||||
\internal
|
||||
*/
|
||||
|
||||
/*! \typedef QContiguousCache::reference
|
||||
\internal
|
||||
*/
|
||||
|
||||
/*! \typedef QContiguousCache::const_reference
|
||||
\internal
|
||||
*/
|
||||
|
||||
/*! \typedef QContiguousCache::difference_type
|
||||
\internal
|
||||
*/
|
||||
|
||||
/*! \typedef QContiguousCache::size_type
|
||||
\internal
|
||||
*/
|
||||
|
||||
/*! \fn QContiguousCache<T> &QContiguousCache::operator=(const QContiguousCache<T> &other)
|
||||
|
||||
Assigns \a other to this cache and returns a reference to this cache.
|
||||
*/
|
||||
|
||||
/*! \fn void QContiguousCache::swap(QContiguousCache<T> &other)
|
||||
\since 4.8
|
||||
|
||||
Swaps cache \a other with this cache. This operation is very
|
||||
fast and never fails.
|
||||
*/
|
||||
|
||||
/*! \fn bool QContiguousCache::operator==(const QContiguousCache<T> &other) const
|
||||
|
||||
Returns true if \a other is equal to this cache; otherwise returns false.
|
||||
|
||||
Two caches are considered equal if they contain the same values at the same
|
||||
indexes. This function requires the value type to implement the \c operator==().
|
||||
|
||||
\sa operator!=()
|
||||
*/
|
||||
|
||||
/*! \fn bool QContiguousCache::operator!=(const QContiguousCache<T> &other) const
|
||||
|
||||
Returns true if \a other is not equal to this cache; otherwise
|
||||
returns false.
|
||||
|
||||
Two caches are considered equal if they contain the same values at the same
|
||||
indexes. This function requires the value type to implement the \c operator==().
|
||||
|
||||
\sa operator==()
|
||||
*/
|
||||
|
||||
/*! \fn int QContiguousCache::capacity() const
|
||||
|
||||
Returns the number of items the cache can store before it is full.
|
||||
When a cache contains a number of items equal to its capacity, adding new
|
||||
items will cause items farthest from the added item to be removed.
|
||||
|
||||
\sa setCapacity(), size()
|
||||
*/
|
||||
|
||||
/*! \fn int QContiguousCache::count() const
|
||||
|
||||
Same as size().
|
||||
*/
|
||||
|
||||
/*! \fn int QContiguousCache::size() const
|
||||
|
||||
Returns the number of items contained within the cache.
|
||||
|
||||
\sa capacity()
|
||||
*/
|
||||
|
||||
/*! \fn bool QContiguousCache::isEmpty() const
|
||||
|
||||
Returns true if no items are stored within the cache.
|
||||
|
||||
\sa size(), capacity()
|
||||
*/
|
||||
|
||||
/*! \fn bool QContiguousCache::isFull() const
|
||||
|
||||
Returns true if the number of items stored within the cache is equal
|
||||
to the capacity of the cache.
|
||||
|
||||
\sa size(), capacity()
|
||||
*/
|
||||
|
||||
/*! \fn int QContiguousCache::available() const
|
||||
|
||||
Returns the number of items that can be added to the cache before it becomes full.
|
||||
|
||||
\sa size(), capacity(), isFull()
|
||||
*/
|
||||
|
||||
/*! \fn void QContiguousCache::clear()
|
||||
|
||||
Removes all items from the cache. The capacity is unchanged.
|
||||
*/
|
||||
|
||||
/*! \fn void QContiguousCache::setCapacity(int size)
|
||||
|
||||
Sets the capacity of the cache to the given \a size. A cache can hold a
|
||||
number of items equal to its capacity. When inserting, appending or prepending
|
||||
items to the cache, if the cache is already full then the item farthest from
|
||||
the added item will be removed.
|
||||
|
||||
If the given \a size is smaller than the current count of items in the cache
|
||||
then only the last \a size items from the cache will remain.
|
||||
|
||||
\sa capacity(), isFull()
|
||||
*/
|
||||
|
||||
/*! \fn const T &QContiguousCache::at(int i) const
|
||||
|
||||
Returns the item at index position \a i in the cache. \a i must
|
||||
be a valid index position in the cache (i.e, firstIndex() <= \a i <= lastIndex()).
|
||||
|
||||
The indexes in the cache refer to the number of positions the item is from the
|
||||
first item appended into the cache. That is to say a cache with a capacity of
|
||||
100, that has had 150 items appended will have a valid index range of
|
||||
50 to 149. This allows inserting and retrieving items into the cache based
|
||||
on a theoretical infinite list
|
||||
|
||||
\sa firstIndex(), lastIndex(), insert(), operator[]()
|
||||
*/
|
||||
|
||||
/*! \fn T &QContiguousCache::operator[](int i)
|
||||
|
||||
Returns the item at index position \a i as a modifiable reference. If
|
||||
the cache does not contain an item at the given index position \a i
|
||||
then it will first insert an empty item at that position.
|
||||
|
||||
In most cases it is better to use either at() or insert().
|
||||
|
||||
\note This non-const overload of operator[] requires QContiguousCache
|
||||
to make a deep copy. Use at() for read-only access to a non-const
|
||||
QContiguousCache.
|
||||
|
||||
\sa insert(), at()
|
||||
*/
|
||||
|
||||
/*! \fn const T &QContiguousCache::operator[](int i) const
|
||||
|
||||
\overload
|
||||
|
||||
Same as at(\a i).
|
||||
*/
|
||||
|
||||
/*! \fn void QContiguousCache::append(const T &value)
|
||||
|
||||
Inserts \a value at the end of the cache. If the cache is already full
|
||||
the item at the start of the cache will be removed.
|
||||
|
||||
\sa prepend(), insert(), isFull()
|
||||
*/
|
||||
|
||||
/*! \fn void QContiguousCache::prepend(const T &value)
|
||||
|
||||
Inserts \a value at the start of the cache. If the cache is already full
|
||||
the item at the end of the cache will be removed.
|
||||
|
||||
\sa append(), insert(), isFull()
|
||||
*/
|
||||
|
||||
/*! \fn void QContiguousCache::insert(int i, const T &value)
|
||||
|
||||
Inserts the \a value at the index position \a i. If the cache already contains
|
||||
an item at \a i then that value is replaced. If \a i is either one more than
|
||||
lastIndex() or one less than firstIndex() it is the equivalent to an append()
|
||||
or a prepend().
|
||||
|
||||
If the given index \a i is not within the current range of the cache nor adjacent
|
||||
to the bounds of the cache's index range, the cache is first cleared before
|
||||
inserting the item. At this point the cache will have a size of 1. It is
|
||||
worthwhile taking effort to insert items in an order that starts adjacent
|
||||
to the current index range for the cache.
|
||||
|
||||
The range of valid indexes for the QContiguousCache class are from
|
||||
0 to INT_MAX. Inserting outside of this range has undefined behavior.
|
||||
|
||||
|
||||
\sa prepend(), append(), isFull(), firstIndex(), lastIndex()
|
||||
*/
|
||||
|
||||
/*! \fn bool QContiguousCache::containsIndex(int i) const
|
||||
|
||||
Returns true if the cache's index range includes the given index \a i.
|
||||
|
||||
\sa firstIndex(), lastIndex()
|
||||
*/
|
||||
|
||||
/*! \fn int QContiguousCache::firstIndex() const
|
||||
|
||||
Returns the first valid index in the cache. The index will be invalid if the
|
||||
cache is empty.
|
||||
|
||||
\sa capacity(), size(), lastIndex()
|
||||
*/
|
||||
|
||||
/*! \fn int QContiguousCache::lastIndex() const
|
||||
|
||||
Returns the last valid index in the cache. The index will be invalid if the cache is empty.
|
||||
|
||||
\sa capacity(), size(), firstIndex()
|
||||
*/
|
||||
|
||||
|
||||
/*! \fn T &QContiguousCache::first()
|
||||
|
||||
Returns a reference to the first item in the cache. This function
|
||||
assumes that the cache isn't empty.
|
||||
|
||||
\sa last(), isEmpty()
|
||||
*/
|
||||
|
||||
/*! \fn T &QContiguousCache::last()
|
||||
|
||||
Returns a reference to the last item in the cache. This function
|
||||
assumes that the cache isn't empty.
|
||||
|
||||
\sa first(), isEmpty()
|
||||
*/
|
||||
|
||||
/*! \fn const T& QContiguousCache::first() const
|
||||
|
||||
\overload
|
||||
*/
|
||||
|
||||
/*! \fn const T& QContiguousCache::last() const
|
||||
|
||||
\overload
|
||||
*/
|
||||
|
||||
/*! \fn void QContiguousCache::removeFirst()
|
||||
|
||||
Removes the first item from the cache. This function assumes that
|
||||
the cache isn't empty.
|
||||
|
||||
\sa removeLast()
|
||||
*/
|
||||
|
||||
/*! \fn void QContiguousCache::removeLast()
|
||||
|
||||
Removes the last item from the cache. This function assumes that
|
||||
the cache isn't empty.
|
||||
|
||||
\sa removeFirst()
|
||||
*/
|
||||
|
||||
/*! \fn T QContiguousCache::takeFirst()
|
||||
|
||||
Removes the first item in the cache and returns it. This function
|
||||
assumes that the cache isn't empty.
|
||||
|
||||
If you don't use the return value, removeFirst() is more efficient.
|
||||
|
||||
\sa takeLast(), removeFirst()
|
||||
*/
|
||||
|
||||
/*! \fn T QContiguousCache::takeLast()
|
||||
|
||||
Removes the last item in the cache and returns it. This function
|
||||
assumes that the cache isn't empty.
|
||||
|
||||
If you don't use the return value, removeLast() is more efficient.
|
||||
|
||||
\sa takeFirst(), removeLast()
|
||||
*/
|
||||
|
||||
/*! \fn void QContiguousCache::normalizeIndexes()
|
||||
|
||||
Moves the first index and last index of the cache
|
||||
such that they point to valid indexes. The function does not modify
|
||||
the contents of the cache or the ordering of elements within the cache.
|
||||
|
||||
It is provided so that index overflows can be corrected when using the
|
||||
cache as a circular buffer.
|
||||
|
||||
\code
|
||||
QContiguousCache<int> cache(10);
|
||||
cache.insert(INT_MAX, 1); // cache contains one value and has valid indexes, INT_MAX to INT_MAX
|
||||
cache.append(2); // cache contains two values but does not have valid indexes.
|
||||
cache.normalizeIndexes(); // cache has two values, 1 and 2. New first index will be in the range of 0 to capacity().
|
||||
\endcode
|
||||
|
||||
\sa areIndexesValid(), append(), prepend()
|
||||
*/
|
||||
|
||||
/*! \fn bool QContiguousCache::areIndexesValid() const
|
||||
|
||||
Returns whether the indexes for items stored in the cache are valid.
|
||||
Indexes can become invalid if items are appended after the index position
|
||||
INT_MAX or prepended before the index position 0. This is only expected
|
||||
to occur in very long lived circular buffer style usage of the
|
||||
contiguous cache. Indexes can be made valid again by calling
|
||||
normalizeIndexs().
|
||||
|
||||
\sa normalizeIndexes(), append(), prepend()
|
||||
*/
|
||||
|
||||
QT_END_NAMESPACE
|
|
@ -1,424 +0,0 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2015 The Qt Company Ltd.
|
||||
** Copyright (C) 2016 Ivailo Monev
|
||||
**
|
||||
** This file is part of the QtCore module of the Katie Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** This file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QCONTIGUOUSCACHE_H
|
||||
#define QCONTIGUOUSCACHE_H
|
||||
|
||||
#include <QtCore/qatomic.h>
|
||||
|
||||
#include <limits.h>
|
||||
#include <cstdlib>
|
||||
#include <new>
|
||||
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
#undef QT_QCONTIGUOUSCACHE_DEBUG
|
||||
|
||||
|
||||
struct Q_CORE_EXPORT QContiguousCacheData
|
||||
{
|
||||
QAtomicInt ref;
|
||||
int alloc;
|
||||
int count;
|
||||
int start;
|
||||
int offset;
|
||||
|
||||
#ifdef QT_QCONTIGUOUSCACHE_DEBUG
|
||||
void dump() const;
|
||||
#endif
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct QContiguousCacheTypedData: private QContiguousCacheData
|
||||
{
|
||||
// private inheritance to avoid aliasing warningss
|
||||
T array[1];
|
||||
|
||||
static inline void free(QContiguousCacheTypedData *data) { ::free(data); }
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class Q_CORE_EXPORT QContiguousCache {
|
||||
typedef QContiguousCacheTypedData<T> Data;
|
||||
union { QContiguousCacheData *d; QContiguousCacheTypedData<T> *p; };
|
||||
public:
|
||||
// STL compatibility
|
||||
typedef T value_type;
|
||||
typedef value_type* pointer;
|
||||
typedef const value_type* const_pointer;
|
||||
typedef value_type& reference;
|
||||
typedef const value_type& const_reference;
|
||||
typedef qptrdiff difference_type;
|
||||
typedef int size_type;
|
||||
|
||||
explicit QContiguousCache(int capacity = 0);
|
||||
QContiguousCache(const QContiguousCache<T> &v) : d(v.d) { d->ref.ref(); }
|
||||
|
||||
inline ~QContiguousCache() { if (!d) return; if (!d->ref.deref()) free(p); }
|
||||
|
||||
QContiguousCache<T> &operator=(const QContiguousCache<T> &other);
|
||||
inline QContiguousCache<T> &operator=(QContiguousCache<T> &&other)
|
||||
{ qSwap(d, other.d); return *this; }
|
||||
inline void swap(QContiguousCache<T> &other) { qSwap(d, other.d); }
|
||||
bool operator==(const QContiguousCache<T> &other) const;
|
||||
inline bool operator!=(const QContiguousCache<T> &other) const { return !(*this == other); }
|
||||
|
||||
inline int capacity() const {return d->alloc; }
|
||||
inline int count() const { return d->count; }
|
||||
inline int size() const { return d->count; }
|
||||
|
||||
inline bool isEmpty() const { return d->count == 0; }
|
||||
inline bool isFull() const { return d->count == d->alloc; }
|
||||
inline int available() const { return d->alloc - d->count; }
|
||||
|
||||
void clear();
|
||||
void setCapacity(int size);
|
||||
|
||||
const T &at(int pos) const;
|
||||
T &operator[](int i);
|
||||
const T &operator[](int i) const;
|
||||
|
||||
void append(const T &value);
|
||||
void prepend(const T &value);
|
||||
void insert(int pos, const T &value);
|
||||
|
||||
inline bool containsIndex(int pos) const { return pos >= d->offset && pos - d->offset < d->count; }
|
||||
inline int firstIndex() const { return d->offset; }
|
||||
inline int lastIndex() const { return d->offset + d->count - 1; }
|
||||
|
||||
inline const T &first() const { Q_ASSERT(!isEmpty()); return p->array[d->start]; }
|
||||
inline const T &last() const { Q_ASSERT(!isEmpty()); return p->array[(d->start + d->count -1) % d->alloc]; }
|
||||
inline T &first() { Q_ASSERT(!isEmpty()); detach(); return p->array[d->start]; }
|
||||
inline T &last() { Q_ASSERT(!isEmpty()); detach(); return p->array[(d->start + d->count -1) % d->alloc]; }
|
||||
|
||||
void removeFirst();
|
||||
T takeFirst();
|
||||
void removeLast();
|
||||
T takeLast();
|
||||
|
||||
inline bool areIndexesValid() const
|
||||
{ return d->offset >= 0 && d->offset < INT_MAX - d->count && (d->offset % d->alloc) == d->start; }
|
||||
|
||||
inline void normalizeIndexes() { d->offset = d->start; }
|
||||
|
||||
#ifdef QT_QCONTIGUOUSCACHE_DEBUG
|
||||
void dump() const { p->dump(); }
|
||||
#endif
|
||||
private:
|
||||
inline void detach() { if (d->ref != 1) detach_helper(); }
|
||||
void detach_helper();
|
||||
|
||||
QContiguousCacheData *allocate(int aalloc);
|
||||
void free(Data *x);
|
||||
int sizeOfTypedData() {
|
||||
// this is more or less the same as sizeof(Data), except that it doesn't
|
||||
// count the padding at the end
|
||||
return reinterpret_cast<const char *>(&(reinterpret_cast<const Data *>(this))->array[1]) - reinterpret_cast<const char *>(this);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
void QContiguousCache<T>::detach_helper()
|
||||
{
|
||||
union { QContiguousCacheData *d; QContiguousCacheTypedData<T> *p; } x;
|
||||
|
||||
x.d = allocate(d->alloc);
|
||||
x.d->ref = 1;
|
||||
x.d->count = d->count;
|
||||
x.d->start = d->start;
|
||||
x.d->offset = d->offset;
|
||||
x.d->alloc = d->alloc;
|
||||
|
||||
T *dest = x.p->array + x.d->start;
|
||||
T *src = p->array + d->start;
|
||||
int oldcount = x.d->count;
|
||||
while (oldcount--) {
|
||||
if (QTypeInfo<T>::isComplex) {
|
||||
new (dest) T(*src);
|
||||
} else {
|
||||
*dest = *src;
|
||||
}
|
||||
dest++;
|
||||
if (dest == x.p->array + x.d->alloc)
|
||||
dest = x.p->array;
|
||||
src++;
|
||||
if (src == p->array + d->alloc)
|
||||
src = p->array;
|
||||
}
|
||||
|
||||
if (!d->ref.deref())
|
||||
free(p);
|
||||
d = x.d;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void QContiguousCache<T>::setCapacity(int asize)
|
||||
{
|
||||
if (asize == d->alloc)
|
||||
return;
|
||||
detach();
|
||||
union { QContiguousCacheData *d; QContiguousCacheTypedData<T> *p; } x;
|
||||
x.d = allocate(asize);
|
||||
x.d->alloc = asize;
|
||||
x.d->count = qMin(d->count, asize);
|
||||
x.d->offset = d->offset + d->count - x.d->count;
|
||||
if(asize)
|
||||
x.d->start = x.d->offset % x.d->alloc;
|
||||
else
|
||||
x.d->start = 0;
|
||||
|
||||
int oldcount = x.d->count;
|
||||
if(oldcount)
|
||||
{
|
||||
T *dest = x.p->array + (x.d->start + x.d->count-1) % x.d->alloc;
|
||||
T *src = p->array + (d->start + d->count-1) % d->alloc;
|
||||
while (oldcount--) {
|
||||
if (QTypeInfo<T>::isComplex) {
|
||||
new (dest) T(*src);
|
||||
} else {
|
||||
*dest = *src;
|
||||
}
|
||||
if (dest == x.p->array)
|
||||
dest = x.p->array + x.d->alloc;
|
||||
dest--;
|
||||
if (src == p->array)
|
||||
src = p->array + d->alloc;
|
||||
src--;
|
||||
}
|
||||
}
|
||||
/* free old */
|
||||
free(p);
|
||||
d = x.d;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void QContiguousCache<T>::clear()
|
||||
{
|
||||
if (d->ref == 1) {
|
||||
if (QTypeInfo<T>::isComplex) {
|
||||
int oldcount = d->count;
|
||||
T * i = p->array + d->start;
|
||||
T * e = p->array + d->alloc;
|
||||
while (oldcount--) {
|
||||
i->~T();
|
||||
i++;
|
||||
if (i == e)
|
||||
i = p->array;
|
||||
}
|
||||
}
|
||||
d->count = d->start = d->offset = 0;
|
||||
} else {
|
||||
union { QContiguousCacheData *d; QContiguousCacheTypedData<T> *p; } x;
|
||||
x.d = allocate(d->alloc);
|
||||
x.d->ref = 1;
|
||||
x.d->alloc = d->alloc;
|
||||
x.d->count = x.d->start = x.d->offset = 0;
|
||||
if (!d->ref.deref()) free(p);
|
||||
d = x.d;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline QContiguousCacheData *QContiguousCache<T>::allocate(int aalloc)
|
||||
{
|
||||
return static_cast<QContiguousCacheData*>(::malloc(sizeOfTypedData() + (aalloc - 1) * sizeof(T)));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
QContiguousCache<T>::QContiguousCache(int cap)
|
||||
{
|
||||
d = allocate(cap);
|
||||
d->ref = 1;
|
||||
d->alloc = cap;
|
||||
d->count = d->start = d->offset = 0;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
QContiguousCache<T> &QContiguousCache<T>::operator=(const QContiguousCache<T> &other)
|
||||
{
|
||||
other.d->ref.ref();
|
||||
if (!d->ref.deref())
|
||||
free(d);
|
||||
d = other.d;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool QContiguousCache<T>::operator==(const QContiguousCache<T> &other) const
|
||||
{
|
||||
if (other.d == d)
|
||||
return true;
|
||||
if (other.d->start != d->start
|
||||
|| other.d->count != d->count
|
||||
|| other.d->offset != d->offset
|
||||
|| other.d->alloc != d->alloc)
|
||||
return false;
|
||||
for (int i = firstIndex(); i <= lastIndex(); ++i)
|
||||
if (!(at(i) == other.at(i)))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void QContiguousCache<T>::free(Data *x)
|
||||
{
|
||||
if (QTypeInfo<T>::isComplex) {
|
||||
int oldcount = d->count;
|
||||
T * i = p->array + d->start;
|
||||
T * e = p->array + d->alloc;
|
||||
while (oldcount--) {
|
||||
i->~T();
|
||||
i++;
|
||||
if (i == e)
|
||||
i = p->array;
|
||||
}
|
||||
}
|
||||
x->free(x);
|
||||
}
|
||||
template <typename T>
|
||||
void QContiguousCache<T>::append(const T &value)
|
||||
{
|
||||
if (!d->alloc)
|
||||
return; // zero capacity
|
||||
detach();
|
||||
if (QTypeInfo<T>::isComplex) {
|
||||
if (d->count == d->alloc)
|
||||
(p->array + (d->start+d->count) % d->alloc)->~T();
|
||||
new (p->array + (d->start+d->count) % d->alloc) T(value);
|
||||
} else {
|
||||
p->array[(d->start+d->count) % d->alloc] = value;
|
||||
}
|
||||
|
||||
if (d->count == d->alloc) {
|
||||
d->start++;
|
||||
d->start %= d->alloc;
|
||||
d->offset++;
|
||||
} else {
|
||||
d->count++;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void QContiguousCache<T>::prepend(const T &value)
|
||||
{
|
||||
if (!d->alloc)
|
||||
return; // zero capacity
|
||||
detach();
|
||||
if (d->start)
|
||||
d->start--;
|
||||
else
|
||||
d->start = d->alloc-1;
|
||||
d->offset--;
|
||||
|
||||
if (d->count != d->alloc)
|
||||
d->count++;
|
||||
else
|
||||
if (d->count == d->alloc)
|
||||
(p->array + d->start)->~T();
|
||||
|
||||
if (QTypeInfo<T>::isComplex)
|
||||
new (p->array + d->start) T(value);
|
||||
else
|
||||
p->array[d->start] = value;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void QContiguousCache<T>::insert(int pos, const T &value)
|
||||
{
|
||||
Q_ASSERT_X(pos >= 0 && pos < INT_MAX, "QContiguousCache<T>::insert", "index out of range");
|
||||
if (!d->alloc)
|
||||
return; // zero capacity
|
||||
detach();
|
||||
if (containsIndex(pos)) {
|
||||
if (QTypeInfo<T>::isComplex) {
|
||||
(p->array + pos % d->alloc)->~T();
|
||||
new (p->array + pos % d->alloc) T(value);
|
||||
} else {
|
||||
p->array[pos % d->alloc] = value;
|
||||
}
|
||||
} else if (pos == d->offset-1)
|
||||
prepend(value);
|
||||
else if (pos == d->offset+d->count)
|
||||
append(value);
|
||||
else {
|
||||
// we don't leave gaps.
|
||||
clear();
|
||||
d->offset = pos;
|
||||
d->start = pos % d->alloc;
|
||||
d->count = 1;
|
||||
if (QTypeInfo<T>::isComplex)
|
||||
new (p->array + d->start) T(value);
|
||||
else
|
||||
p->array[d->start] = value;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline const T &QContiguousCache<T>::at(int pos) const
|
||||
{ Q_ASSERT_X(pos >= d->offset && pos - d->offset < d->count, "QContiguousCache<T>::at", "index out of range"); return p->array[pos % d->alloc]; }
|
||||
template <typename T>
|
||||
inline const T &QContiguousCache<T>::operator[](int pos) const
|
||||
{ Q_ASSERT_X(pos >= d->offset && pos - d->offset < d->count, "QContiguousCache<T>::at", "index out of range"); return p->array[pos % d->alloc]; }
|
||||
|
||||
template <typename T>
|
||||
inline T &QContiguousCache<T>::operator[](int pos)
|
||||
{
|
||||
detach();
|
||||
if (!containsIndex(pos))
|
||||
insert(pos, T());
|
||||
return p->array[pos % d->alloc];
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void QContiguousCache<T>::removeFirst()
|
||||
{
|
||||
Q_ASSERT(d->count > 0);
|
||||
detach();
|
||||
d->count--;
|
||||
if (QTypeInfo<T>::isComplex)
|
||||
(p->array + d->start)->~T();
|
||||
d->start = (d->start + 1) % d->alloc;
|
||||
d->offset++;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void QContiguousCache<T>::removeLast()
|
||||
{
|
||||
Q_ASSERT(d->count > 0);
|
||||
detach();
|
||||
d->count--;
|
||||
if (QTypeInfo<T>::isComplex)
|
||||
(p->array + (d->start + d->count) % d->alloc)->~T();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T QContiguousCache<T>::takeFirst()
|
||||
{ T t = first(); removeFirst(); return t; }
|
||||
|
||||
template <typename T>
|
||||
inline T QContiguousCache<T>::takeLast()
|
||||
{ T t = last(); removeLast(); return t; }
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
|
||||
#endif
|
|
@ -24,7 +24,6 @@
|
|||
#include "qdeclarativeevents_p_p.h"
|
||||
#include "qdeclarativeglobal_p.h"
|
||||
#include "qdeclarativeinfo.h"
|
||||
|
||||
#include <QtCore/qmath.h>
|
||||
#include <QTextLayout>
|
||||
#include <QTextDocument>
|
||||
|
@ -34,6 +33,8 @@
|
|||
#include <QPainter>
|
||||
#include "qtextcontrol_p.h"
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
/*!
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
****************************************************************************/
|
||||
|
||||
#include "qdeclarativeobjectscriptclass_p.h"
|
||||
|
||||
#include "qdeclarativeengine_p.h"
|
||||
#include "qdeclarativecontext_p.h"
|
||||
#include "qdeclarativedata_p.h"
|
||||
|
@ -30,11 +29,12 @@
|
|||
#include "qdeclarativeguard_p.h"
|
||||
#include "qdeclarativevmemetaobject_p.h"
|
||||
#include "qdeclarativecommon_p.h"
|
||||
|
||||
#include <QtCore/qtimer.h>
|
||||
#include <QtCore/qvarlengtharray.h>
|
||||
#include <QtScript/qscriptcontextinfo.h>
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
struct ObjectData : public QScriptDeclarativeClass::Object {
|
||||
|
|
|
@ -32,6 +32,8 @@
|
|||
#include "qabstractitemmodel_p.h"
|
||||
#include "qabstractproxymodel_p.h"
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
typedef QList<QPair<QModelIndex, QPersistentModelIndex> > QModelIndexPairList;
|
||||
|
|
|
@ -32,10 +32,11 @@
|
|||
#include <QtCore/qstringlist.h>
|
||||
#include <QtCore/qbitarray.h>
|
||||
#include <QtCore/qmimedata.h>
|
||||
|
||||
#include "qstandarditemmodel_p.h"
|
||||
#include "qdebug.h"
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QStandardItemModelLessThan
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
#include "qpainter.h"
|
||||
#include "qtablewidget_p.h"
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
QTableModel::QTableModel(int rows, int columns, QTableWidget *parent)
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
#include "qdebug.h"
|
||||
#include "qguicommon_p.h"
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
/**
|
||||
The algorithm is as follows:
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
#include <limits.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
|
@ -56,17 +56,13 @@
|
|||
#include "qscriptxmlparser_p.h"
|
||||
#include "qscripttoolscommon_p.h"
|
||||
#include "qscripttoolsresources_p.h"
|
||||
|
||||
#include "qobject_p.h"
|
||||
|
||||
#include <QtScript/qscriptcontext.h>
|
||||
#include <QtScript/qscriptcontextinfo.h>
|
||||
|
||||
#include <QtCore/qcoreapplication.h>
|
||||
#include <QtCore/qdir.h>
|
||||
#include <QtCore/qstringlist.h>
|
||||
#include <QtCore/qdebug.h>
|
||||
|
||||
#include <QtGui/qaction.h>
|
||||
#include <QtGui/qevent.h>
|
||||
#include <QtGui/qicon.h>
|
||||
|
@ -75,6 +71,8 @@
|
|||
#include <QtGui/qtoolbar.h>
|
||||
#include <QtGui/qtooltip.h>
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
// Q_SCRIPT_EXPORT QString qt_scriptToXml(const QString &program, int lineNumber = 1);
|
||||
|
|
|
@ -98,8 +98,6 @@ static const struct ClassTblData {
|
|||
{ QLatin1String("QCommonStyle"), QLatin1String("QtGui/qcommonstyle.h") },
|
||||
{ QLatin1String("QCompleter"), QLatin1String("QtGui/qcompleter.h") },
|
||||
{ QLatin1String("QContextMenuEvent"), QLatin1String("QtGui/qevent.h") },
|
||||
{ QLatin1String("QContiguousCache"), QLatin1String("QtCore/qcontiguouscache.h") },
|
||||
{ QLatin1String("QContiguousCacheData"), QLatin1String("QtCore/qcontiguouscache.h") },
|
||||
{ QLatin1String("QCoreApplication"), QLatin1String("QtCore/qcoreapplication.h") },
|
||||
{ QLatin1String("QCryptographicHash"), QLatin1String("QtNetwork/qcryptographichash.h") },
|
||||
{ QLatin1String("QCursor"), QLatin1String("QtGui/qcursor.h") },
|
||||
|
|
|
@ -34,6 +34,8 @@
|
|||
#include <qdebug.h>
|
||||
#include "../../shared/util.h"
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
typedef QList<int> IntList;
|
||||
Q_DECLARE_METATYPE(IntList)
|
||||
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
#include <qdebug.h>
|
||||
#include <qpoint.h>
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
//TESTED_CLASS=
|
||||
//TESTED_FILES=
|
||||
|
||||
|
|
|
@ -31,6 +31,8 @@
|
|||
#include <qtextobject.h>
|
||||
#include <qdebug.h>
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
//TESTED_FILES=gui/text/qtextcursor.cpp gui/text/qtextcursor_p.h
|
||||
|
||||
class tst_QTextCursor : public QObject
|
||||
|
|
|
@ -31,6 +31,8 @@
|
|||
#include <qtextlayout.h>
|
||||
#include <qabstracttextdocumentlayout.h>
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
//TESTED_CLASS=
|
||||
//TESTED_FILES=
|
||||
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
#include <qtextedit.h>
|
||||
#include <qtextcursor.h>
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
//TESTED_CLASS=
|
||||
//TESTED_FILES=
|
||||
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
katie_test(tst_bench_qcontiguouscache
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
|
||||
)
|
|
@ -1,171 +0,0 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2015 The Qt Company Ltd.
|
||||
** Copyright (C) 2016 Ivailo Monev
|
||||
**
|
||||
** This file is part of the test suite of the Katie Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** This file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QObject>
|
||||
#include <QTest>
|
||||
#include <QCache>
|
||||
#include <QContiguousCache>
|
||||
#include <QDebug>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
QT_USE_NAMESPACE
|
||||
|
||||
class tst_QContiguousCache : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
void asScrollingList();
|
||||
void cacheBenchmark();
|
||||
void contiguousCacheBenchmark();
|
||||
};
|
||||
|
||||
QTEST_MAIN(tst_QContiguousCache)
|
||||
|
||||
void tst_QContiguousCache::asScrollingList()
|
||||
{
|
||||
int i;
|
||||
QContiguousCache<int> c(10);
|
||||
|
||||
// Once allocated QContiguousCache should not
|
||||
// allocate any additional memory for non
|
||||
// complex data types.
|
||||
QBENCHMARK {
|
||||
// simulate scrolling in a list of items;
|
||||
for (i = 0; i < 10; ++i) {
|
||||
QCOMPARE(c.available(), 10-i);
|
||||
c.append(i);
|
||||
}
|
||||
|
||||
QCOMPARE(c.firstIndex(), 0);
|
||||
QCOMPARE(c.lastIndex(), 9);
|
||||
QCOMPARE(c.first(), 0);
|
||||
QCOMPARE(c.last(), 9);
|
||||
QVERIFY(!c.containsIndex(-1));
|
||||
QVERIFY(!c.containsIndex(10));
|
||||
QCOMPARE(c.available(), 0);
|
||||
|
||||
for (i = 0; i < 10; ++i) {
|
||||
QVERIFY(c.containsIndex(i));
|
||||
QCOMPARE(c.at(i), i);
|
||||
QCOMPARE(c[i], i);
|
||||
QCOMPARE(((const QContiguousCache<int>)c)[i], i);
|
||||
}
|
||||
|
||||
for (i = 10; i < 30; ++i)
|
||||
c.append(i);
|
||||
|
||||
QCOMPARE(c.firstIndex(), 20);
|
||||
QCOMPARE(c.lastIndex(), 29);
|
||||
QCOMPARE(c.first(), 20);
|
||||
QCOMPARE(c.last(), 29);
|
||||
QVERIFY(!c.containsIndex(19));
|
||||
QVERIFY(!c.containsIndex(30));
|
||||
QCOMPARE(c.available(), 0);
|
||||
|
||||
for (i = 20; i < 30; ++i) {
|
||||
QVERIFY(c.containsIndex(i));
|
||||
QCOMPARE(c.at(i), i);
|
||||
QCOMPARE(c[i], i);
|
||||
QCOMPARE(((const QContiguousCache<int> )c)[i], i);
|
||||
}
|
||||
|
||||
for (i = 19; i >= 10; --i)
|
||||
c.prepend(i);
|
||||
|
||||
QCOMPARE(c.firstIndex(), 10);
|
||||
QCOMPARE(c.lastIndex(), 19);
|
||||
QCOMPARE(c.first(), 10);
|
||||
QCOMPARE(c.last(), 19);
|
||||
QVERIFY(!c.containsIndex(9));
|
||||
QVERIFY(!c.containsIndex(20));
|
||||
QCOMPARE(c.available(), 0);
|
||||
|
||||
for (i = 10; i < 20; ++i) {
|
||||
QVERIFY(c.containsIndex(i));
|
||||
QCOMPARE(c.at(i), i);
|
||||
QCOMPARE(c[i], i);
|
||||
QCOMPARE(((const QContiguousCache<int> )c)[i], i);
|
||||
}
|
||||
|
||||
for (i = 200; i < 220; ++i)
|
||||
c.insert(i, i);
|
||||
|
||||
QCOMPARE(c.firstIndex(), 210);
|
||||
QCOMPARE(c.lastIndex(), 219);
|
||||
QCOMPARE(c.first(), 210);
|
||||
QCOMPARE(c.last(), 219);
|
||||
QVERIFY(!c.containsIndex(209));
|
||||
QVERIFY(!c.containsIndex(300));
|
||||
QCOMPARE(c.available(), 0);
|
||||
|
||||
for (i = 210; i < 220; ++i) {
|
||||
QVERIFY(c.containsIndex(i));
|
||||
QCOMPARE(c.at(i), i);
|
||||
QCOMPARE(c[i], i);
|
||||
QCOMPARE(((const QContiguousCache<int> )c)[i], i);
|
||||
}
|
||||
c.clear(); // needed to reset benchmark
|
||||
}
|
||||
|
||||
// from a specific bug that was encountered. 100 to 299 cached, attempted to cache 250 - 205 via insert, failed.
|
||||
// bug was that item at 150 would instead be item that should have been inserted at 250
|
||||
c.setCapacity(200);
|
||||
for (i = 100; i < 300; ++i)
|
||||
c.insert(i, i);
|
||||
for (i = 250; i <= 306; ++i)
|
||||
c.insert(i, 1000+i);
|
||||
for (i = 107; i <= 306; ++i) {
|
||||
QVERIFY(c.containsIndex(i));
|
||||
QCOMPARE(c.at(i), i < 250 ? i : 1000+i);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Benchmarks must be near identical in tasks to be fair.
|
||||
QCache uses pointers to ints as its a requirement of QCache,
|
||||
whereas QContiguousCache doesn't support pointers (won't free them).
|
||||
Given the ability to use simple data types is a benefit, its
|
||||
fair. Although this obviously must take into account we are
|
||||
testing QContiguousCache use cases here, QCache has its own
|
||||
areas where it is the more sensible class to use.
|
||||
*/
|
||||
void tst_QContiguousCache::cacheBenchmark()
|
||||
{
|
||||
QBENCHMARK {
|
||||
QCache<int, int> cache;
|
||||
cache.setMaxCost(100);
|
||||
|
||||
for (int i = 0; i < 1000; i++)
|
||||
cache.insert(i, new int(i));
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QContiguousCache::contiguousCacheBenchmark()
|
||||
{
|
||||
QBENCHMARK {
|
||||
QContiguousCache<int> contiguousCache(100);
|
||||
for (int i = 0; i < 1000; i++)
|
||||
contiguousCache.insert(i, i);
|
||||
}
|
||||
}
|
||||
|
||||
#include "moc_main.cpp"
|
Loading…
Add table
Reference in a new issue