Array-backed containers: add shrink_to_fit for STL compatibility

Side note: QHash has squeeze(), but there's no shrink_to_fit on
std::unordered_map.

[ChangeLog][QtCore][QByteArray] Added shrink_to_fit().

[ChangeLog][QtCore][QString] Added shrink_to_fit().

[ChangeLog][QtCore][QVarLengthArray] Added shrink_to_fit().

[ChangeLog][QtCore][QVector] Added shrink_to_fit().

Change-Id: Ifd7d28c9bed70727be6308f0191a188201784f61
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
bb10
Giuseppe D'Angelo 2017-04-08 21:25:42 +02:00
parent 58a4f41af2
commit 9dff809b45
8 changed files with 33 additions and 0 deletions

View File

@ -1134,6 +1134,13 @@ static inline char qToLower(char c)
Same as prepend(\a ch).
*/
/*! \fn void QByteArray::shrink_to_fit()
\since 5.10
This function is provided for STL compatibility. It is equivalent to
squeeze().
*/
/*! \fn QByteArray::QByteArray(const QByteArray &other)
Constructs a copy of \a other.

View File

@ -423,6 +423,7 @@ public:
inline void push_front(char c);
inline void push_front(const char *c);
inline void push_front(const QByteArray &a);
void shrink_to_fit() { squeeze(); }
static inline QByteArray fromStdString(const std::string &s);
inline std::string toStdString() const;

View File

@ -8469,6 +8469,15 @@ bool QString::isRightToLeft() const
Appends the given \a ch character onto the end of this string.
*/
/*! \fn void QString::shrink_to_fit()
\since 5.10
This function is provided for STL compatibility. It is
equivalent to squeeze().
\sa squeeze()
*/
/*!
\fn std::string QString::toStdString() const

View File

@ -805,6 +805,7 @@ public:
inline void push_back(const QString &s) { append(s); }
inline void push_front(QChar c) { prepend(c); }
inline void push_front(const QString &s) { prepend(s); }
void shrink_to_fit() { squeeze(); }
static inline QString fromStdString(const std::string &s);
inline std::string toStdString() const;

View File

@ -231,6 +231,7 @@ public:
inline const T &front() const { return first(); }
inline T &back() { return last(); }
inline const T &back() const { return last(); }
void shrink_to_fit() { squeeze(); }
private:
void realloc(int size, int alloc);

View File

@ -190,6 +190,12 @@
\overload
*/
/*! \fn void QVarLengthArray::shrink_to_fit()
\since 5.10
Same as squeeze(). Provided for STL-compatibility.
*/
/*! \fn bool QVarLengthArray::isEmpty() const
Returns \c true if the array has size 0; otherwise returns \c false.

View File

@ -268,6 +268,7 @@ public:
inline const_reference front() const { return first(); }
inline reference back() { return last(); }
inline const_reference back() const { return last(); }
void shrink_to_fit() { squeeze(); }
// comfort
QVector<T> &operator+=(const QVector<T> &l);

View File

@ -1124,6 +1124,13 @@
\overload
*/
/*! \fn void QVector::shrink_to_fit()
\since 5.10
This function is provided for STL compatibility. It is equivalent
to squeeze().
*/
/*! \fn bool QVector::empty() const
This function is provided for STL compatibility. It is equivalent