summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAhmad Samir <a.samirh78@gmail.com>2022-10-25 14:46:52 +0200
committerAhmad Samir <a.samirh78@gmail.com>2022-11-16 18:25:35 +0200
commit4c975fd564e3b1f5c398f6ffe6b4b87ff6f95379 (patch)
tree8e30ad17da7a020910c737167cdc64f4204d26db /src
parente5f777638b6a32adc6245bf276af9c887b4c9b0f (diff)
QString: refactor removeStringImpl()
Use std::copy() instead of memmove(), cppreference.com docs mentions that it will use memmove() internally, I confirmed that by following the code in gdb, I did see that it uses:. __builtin_memmove(__result, __first, sizeof(_Tp) * _Num); in /usr/include/c++/12/bits/stl_algobase.h std::copy is more readable / easier-to-use API than memmove. Change-Id: Iccb2fa1dc9897fd6a922ef96bc25308493d39eac Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/text/qstring.cpp14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp
index 707b13082a..fe5f8ae5f1 100644
--- a/src/corelib/text/qstring.cpp
+++ b/src/corelib/text/qstring.cpp
@@ -3325,21 +3325,19 @@ static void removeStringImpl(QString &s, const T &needle, Qt::CaseSensitivity cs
if (i < 0)
return;
- const auto beg = s.begin(); // detaches
+ auto beg = s.begin(); // detaches
auto dst = beg + i;
auto src = beg + i + needleSize;
- const auto end = s.end();
+ auto end = s.end();
// loop invariant: [beg, dst[ is partial result
// [src, end[ still to be checked for needles
while (src < end) {
- const auto i = s.indexOf(needle, src - beg, cs);
- const auto hit = i == -1 ? end : beg + i;
- const auto skipped = hit - src;
- memmove(dst, src, skipped * sizeof(QChar));
- dst += skipped;
+ i = s.indexOf(needle, std::distance(beg, src), cs);
+ auto hit = i == -1 ? end : beg + i;
+ dst = std::copy(src, hit, dst);
src = hit + needleSize;
}
- s.truncate(dst - beg);
+ s.truncate(std::distance(beg, dst));
}
/*!