summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2017-04-08 21:25:42 +0200
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2017-04-12 11:32:18 +0000
commit9dff809b452b0b69f5583cd0c131c65991631200 (patch)
tree39dbc2b9bbaba0b89f7d83e40ea4efeae7247e40 /src/corelib/tools
parent58a4f41af2b27957bc9dac89df21051620e3d2ec (diff)
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>
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qbytearray.cpp7
-rw-r--r--src/corelib/tools/qbytearray.h1
-rw-r--r--src/corelib/tools/qstring.cpp9
-rw-r--r--src/corelib/tools/qstring.h1
-rw-r--r--src/corelib/tools/qvarlengtharray.h1
-rw-r--r--src/corelib/tools/qvarlengtharray.qdoc6
-rw-r--r--src/corelib/tools/qvector.h1
-rw-r--r--src/corelib/tools/qvector.qdoc7
8 files changed, 33 insertions, 0 deletions
diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp
index 6be28fea5f..c728a05f55 100644
--- a/src/corelib/tools/qbytearray.cpp
+++ b/src/corelib/tools/qbytearray.cpp
@@ -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.
diff --git a/src/corelib/tools/qbytearray.h b/src/corelib/tools/qbytearray.h
index 76660d9289..3fc6718abb 100644
--- a/src/corelib/tools/qbytearray.h
+++ b/src/corelib/tools/qbytearray.h
@@ -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;
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
index 4a92a7f424..07d6376b85 100644
--- a/src/corelib/tools/qstring.cpp
+++ b/src/corelib/tools/qstring.cpp
@@ -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
diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h
index 05d411d138..f65331f7e4 100644
--- a/src/corelib/tools/qstring.h
+++ b/src/corelib/tools/qstring.h
@@ -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;
diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h
index 9879d55967..90311ac55b 100644
--- a/src/corelib/tools/qvarlengtharray.h
+++ b/src/corelib/tools/qvarlengtharray.h
@@ -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);
diff --git a/src/corelib/tools/qvarlengtharray.qdoc b/src/corelib/tools/qvarlengtharray.qdoc
index 127afcd069..be2bdeda07 100644
--- a/src/corelib/tools/qvarlengtharray.qdoc
+++ b/src/corelib/tools/qvarlengtharray.qdoc
@@ -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.
diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h
index fd124d1d59..121187083b 100644
--- a/src/corelib/tools/qvector.h
+++ b/src/corelib/tools/qvector.h
@@ -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);
diff --git a/src/corelib/tools/qvector.qdoc b/src/corelib/tools/qvector.qdoc
index 0ea47b1a1a..61fb3d494d 100644
--- a/src/corelib/tools/qvector.qdoc
+++ b/src/corelib/tools/qvector.qdoc
@@ -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