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>
bb10
Edward Welbourne 2021-08-02 17:31:20 +02:00
parent ccec95fda6
commit 47ead6ce2c
1 changed files with 4 additions and 13 deletions

View File

@ -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)