QContainerTools: add q_points_into_range overload
Looking at the use-cases of the already existing q_points_into_range overload, all of them can be ported to the new one (i.e. all of them were using range [begin, end)). Change-Id: I4bfdd68271512b88a9800a16237ff967a367eaeb Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
fa2153bd10
commit
2fe3b0e564
@ -2151,7 +2151,7 @@ QByteArray &QByteArray::insert(qsizetype i, QByteArrayView data)
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!d->needsDetach() && QtPrivate::q_points_into_range(str, d.data(), d.data() + d.size)) {
|
if (!d->needsDetach() && QtPrivate::q_points_into_range(str, d)) {
|
||||||
QVarLengthArray a(str, str + size);
|
QVarLengthArray a(str, str + size);
|
||||||
return insert(i, a);
|
return insert(i, a);
|
||||||
}
|
}
|
||||||
@ -2327,7 +2327,7 @@ QByteArray &QByteArray::remove(qsizetype pos, qsizetype len)
|
|||||||
|
|
||||||
QByteArray &QByteArray::replace(qsizetype pos, qsizetype len, QByteArrayView after)
|
QByteArray &QByteArray::replace(qsizetype pos, qsizetype len, QByteArrayView after)
|
||||||
{
|
{
|
||||||
if (QtPrivate::q_points_into_range(after.data(), d.data(), d.data() + d.size)) {
|
if (QtPrivate::q_points_into_range(after.data(), d)) {
|
||||||
QVarLengthArray copy(after.data(), after.data() + after.size());
|
QVarLengthArray copy(after.data(), after.data() + after.size());
|
||||||
return replace(pos, len, QByteArrayView{copy});
|
return replace(pos, len, QByteArrayView{copy});
|
||||||
}
|
}
|
||||||
@ -2387,11 +2387,11 @@ QByteArray &QByteArray::replace(QByteArrayView before, QByteArrayView after)
|
|||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
// protect against before or after being part of this
|
// protect against before or after being part of this
|
||||||
if (QtPrivate::q_points_into_range(a, d.data(), d.data() + d.size)) {
|
if (QtPrivate::q_points_into_range(a, d)) {
|
||||||
QVarLengthArray copy(a, a + asize);
|
QVarLengthArray copy(a, a + asize);
|
||||||
return replace(before, QByteArrayView{copy});
|
return replace(before, QByteArrayView{copy});
|
||||||
}
|
}
|
||||||
if (QtPrivate::q_points_into_range(b, d.data(), d.data() + d.size)) {
|
if (QtPrivate::q_points_into_range(b, d)) {
|
||||||
QVarLengthArray copy(b, b + bsize);
|
QVarLengthArray copy(b, b + bsize);
|
||||||
return replace(QByteArrayView{copy}, after);
|
return replace(QByteArrayView{copy}, after);
|
||||||
}
|
}
|
||||||
|
@ -821,7 +821,7 @@ static qsizetype defaultIndex()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
using QtPrivate::q_points_into_range;
|
using QtPrivate::q_points_into_range;
|
||||||
Q_ASSERT(q_points_into_range(data, locale_data, std::end(locale_data)));
|
Q_ASSERT(q_points_into_range(data, locale_data));
|
||||||
return data - locale_data;
|
return data - locale_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -916,11 +916,10 @@ public:
|
|||||||
DataPointer old;
|
DataPointer old;
|
||||||
|
|
||||||
// points into range:
|
// points into range:
|
||||||
if (QtPrivate::q_points_into_range(b, this->begin(), this->end())) {
|
if (QtPrivate::q_points_into_range(b, *this))
|
||||||
this->detachAndGrow(QArrayData::GrowsAtEnd, n, &b, &old);
|
this->detachAndGrow(QArrayData::GrowsAtEnd, n, &b, &old);
|
||||||
} else {
|
else
|
||||||
this->detachAndGrow(QArrayData::GrowsAtEnd, n, nullptr, nullptr);
|
this->detachAndGrow(QArrayData::GrowsAtEnd, n, nullptr, nullptr);
|
||||||
}
|
|
||||||
Q_ASSERT(this->freeSpaceAtEnd() >= n);
|
Q_ASSERT(this->freeSpaceAtEnd() >= n);
|
||||||
// b might be updated so use [b, n)
|
// b might be updated so use [b, n)
|
||||||
this->copyAppend(b, b + n);
|
this->copyAppend(b, b + n);
|
||||||
|
@ -300,7 +300,7 @@ public:
|
|||||||
T *res = this->ptr + offset;
|
T *res = this->ptr + offset;
|
||||||
QtPrivate::q_relocate_overlap_n(this->ptr, this->size, res);
|
QtPrivate::q_relocate_overlap_n(this->ptr, this->size, res);
|
||||||
// first update data pointer, then this->ptr
|
// first update data pointer, then this->ptr
|
||||||
if (data && QtPrivate::q_points_into_range(*data, this->begin(), this->end()))
|
if (data && QtPrivate::q_points_into_range(*data, *this))
|
||||||
*data += offset;
|
*data += offset;
|
||||||
this->ptr = res;
|
this->ptr = res;
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,23 @@ static constexpr bool q_points_into_range(const T *p, const T *b, const T *e,
|
|||||||
return !less(p, b) && less(p, e);
|
return !less(p, b) && less(p, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\internal
|
||||||
|
|
||||||
|
Returns whether \a p is within container \a c. In its simplest form equivalent to:
|
||||||
|
c.data() <= p < c.data() + c.size()
|
||||||
|
*/
|
||||||
|
template <typename C, typename T>
|
||||||
|
static constexpr bool q_points_into_range(const T &p, const C &c) noexcept
|
||||||
|
{
|
||||||
|
static_assert(std::is_same_v<decltype(std::data(c)), T>);
|
||||||
|
|
||||||
|
// std::distance because QArrayDataPointer has a "qsizetype size"
|
||||||
|
// member but no size() function
|
||||||
|
return q_points_into_range(p, std::data(c),
|
||||||
|
std::data(c) + std::distance(std::begin(c), std::end(c)));
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T, typename N>
|
template <typename T, typename N>
|
||||||
void q_uninitialized_move_if_noexcept_n(T* first, N n, T* out)
|
void q_uninitialized_move_if_noexcept_n(T* first, N n, T* out)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user