diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2021-08-02 17:31:20 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2021-08-06 14:29:18 +0200 |
commit | 47ead6ce2c562712fe0774cab8ee354b795359f6 (patch) | |
tree | 7ee0b1ea9c828ce382b4500ead8035f2b8b0f42d /src | |
parent | ccec95fda6bedb67139e2049320e929a9acd8f2a (diff) |
replaceArgEscapes(): use a local variable to avoid duplication
Two blocks of code branched on the same local variable and, in each
block, one branch acted on a C-locale text, the other a localized
version, but doing the same to each in the two branches. Branch to set
a variable to the selected text so that we only have to write the code
to do each branch's actions to that one text.
Change-Id: I8bbc1210f2c14b19f41a9974c7b6ec2ae612cc70
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/text/qstring.cpp | 17 |
1 files changed, 4 insertions, 13 deletions
diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index 8e9d34a7a9..d063a8a8eb 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -7817,25 +7817,16 @@ static QString replaceArgEscapes(QStringView s, const ArgEscapeData &d, int fiel memcpy(rc, text_start, (escape_start - text_start)*sizeof(QChar)); rc += escape_start - text_start; - uint pad_chars; - if (localize) - pad_chars = qMax(abs_field_width, larg.length()) - larg.length(); - else - pad_chars = qMax(abs_field_width, arg.length()) - arg.length(); + const QStringView use = localize ? larg : arg; + const uint pad_chars = qMax(abs_field_width, use.length()) - use.length(); if (field_width > 0) { // left padded for (uint i = 0; i < pad_chars; ++i) *rc++ = fillChar; } - if (localize) { - memcpy(rc, larg.data(), larg.length()*sizeof(QChar)); - rc += larg.length(); - } - else { - memcpy(rc, arg.data(), arg.length()*sizeof(QChar)); - rc += arg.length(); - } + memcpy(rc, use.data(), use.length() * sizeof(QChar)); + rc += use.length(); if (field_width < 0) { // right padded for (uint i = 0; i < pad_chars; ++i) |