diff options
| author | Ahmad Samir <a.samirh78@gmail.com> | 2022-10-24 23:58:14 +0200 |
|---|---|---|
| committer | Ahmad Samir <a.samirh78@gmail.com> | 2022-11-03 14:22:51 +0200 |
| commit | f41089ba3da174279d168a4649dad52e8d90cd90 (patch) | |
| tree | 720421ad73ff0fe33440ec7bbd32fb412330ab38 /src/corelib/tools/qarraydataops.h | |
| parent | dcfab7e28ee9bbdf09138a321e1f8db2b770d4b7 (diff) | |
QString: don't detach in remove(pos, len)
- If this string isn't shared, don't call detach, instead use ->erase() as
needed
- If this string is shared, create a new string, and copy all elements
except the ones that would be removed, see task for details
Update unittest to test both code paths.
Task-number: QTBUG-106181
Change-Id: I4c73ff17a6fa89ddcf6966f9c5bf789753f6d39e
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qarraydataops.h')
| -rw-r--r-- | src/corelib/tools/qarraydataops.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/corelib/tools/qarraydataops.h b/src/corelib/tools/qarraydataops.h index afd1a264bd7..13d5572c03e 100644 --- a/src/corelib/tools/qarraydataops.h +++ b/src/corelib/tools/qarraydataops.h @@ -213,6 +213,17 @@ public: --this->size; } + struct Span { T *begin; T *end; }; + + void copyRanges(const std::initializer_list<Span> &ranges) + { + auto it = this->begin(); + std::for_each(ranges.begin(), ranges.end(), [&it](const auto &span) { + it = std::copy(span.begin, span.end, it); + }); + this->size = std::distance(this->begin(), it); + } + void assign(T *b, T *e, parameter_type t) noexcept { Q_ASSERT(b <= e); |
