From 47ead6ce2c562712fe0774cab8ee354b795359f6 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 2 Aug 2021 17:31:20 +0200 Subject: [PATCH] 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 --- src/corelib/text/qstring.cpp | 17 ++++------------- 1 file 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)