QMessagePattern: "precompile" the default pattern
So we don't have to parse it on first use if it isn't set. This should be a small performance gain for everyone who uses the default, which is usually the majority of people. Change-Id: I10c471715457dcfa3a1dfffd2768ce605e4f7e30 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Ahmad Samir <a.samirh78@gmail.com> (cherry picked from commit e04f109456bbcb184963b8ed71944b958b35c201) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
9a1edf52d4
commit
765aa27aa3
@ -1130,18 +1130,29 @@ static const char ifFatalTokenC[] = "%{if-fatal}";
|
||||
static const char endifTokenC[] = "%{endif}";
|
||||
static const char emptyTokenC[] = "";
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
static const char defaultPattern[] = "%{message}";
|
||||
#else
|
||||
static const char defaultPattern[] = "%{if-category}%{category}: %{endif}%{message}";
|
||||
#endif
|
||||
|
||||
struct QMessagePattern
|
||||
{
|
||||
QMessagePattern();
|
||||
~QMessagePattern();
|
||||
|
||||
void setPattern(const QString &pattern);
|
||||
void setDefaultPattern()
|
||||
{
|
||||
const char *const defaultTokens[] = {
|
||||
#ifndef Q_OS_ANDROID
|
||||
// "%{if-category}%{category}: %{endif}%{message}"
|
||||
ifCategoryTokenC,
|
||||
categoryTokenC,
|
||||
": ", // won't point to literals[] but that's ok
|
||||
endifTokenC,
|
||||
#endif
|
||||
messageTokenC,
|
||||
};
|
||||
|
||||
// std::make_unique() value-initializes, so we have a nullptr at the end
|
||||
tokens = std::make_unique<const char *[]>(std::size(defaultTokens) + 1);
|
||||
std::copy(std::begin(defaultTokens), std::end(defaultTokens), tokens.get());
|
||||
}
|
||||
|
||||
// 0 terminated arrays of literal tokens / literal or placeholder tokens
|
||||
std::unique_ptr<std::unique_ptr<const char[]>[]> literals;
|
||||
@ -1188,7 +1199,7 @@ QMessagePattern::QMessagePattern()
|
||||
#endif
|
||||
const QString envPattern = qEnvironmentVariable("QT_MESSAGE_PATTERN");
|
||||
if (envPattern.isEmpty()) {
|
||||
setPattern(QLatin1StringView(defaultPattern));
|
||||
setDefaultPattern();
|
||||
fromEnvironment = false;
|
||||
} else {
|
||||
setPattern(envPattern);
|
||||
|
Loading…
x
Reference in New Issue
Block a user