From 0403f09272b37bfe59a98c7de165b325583f0e77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Mon, 27 Feb 2023 17:36:01 +0100 Subject: [PATCH] DNS Lookup: Avoid unneeded allocations in parsing function By using .compare(~~~, Qt::CaseInsensitive) instead of .toLower() Task-number: QTBUG-108873 Change-Id: I60e1fdc0a54450e7385e90f84fd509e62b82d2c9 Reviewed-by: Timur Pocheptsov Reviewed-by: Konrad Kujawa Reviewed-by: Marc Mutz (cherry picked from commit 5e16397a2cabd963c183a722c6daff6b2a32eada) Reviewed-by: Qt Cherry-pick Bot --- examples/network/dnslookup/dnslookup.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/examples/network/dnslookup/dnslookup.cpp b/examples/network/dnslookup/dnslookup.cpp index 264a8e37fa1..71bb6a8131a 100644 --- a/examples/network/dnslookup/dnslookup.cpp +++ b/examples/network/dnslookup/dnslookup.cpp @@ -13,25 +13,25 @@ #include -static int typeFromParameter(const QString &type) +static int typeFromParameter(QStringView type) { - if (type == "a") + if (type.compare(u"a", Qt::CaseInsensitive) == 0) return QDnsLookup::A; - if (type == "aaaa") + if (type.compare(u"aaaa", Qt::CaseInsensitive) == 0) return QDnsLookup::AAAA; - if (type == "any") + if (type.compare(u"any", Qt::CaseInsensitive) == 0) return QDnsLookup::ANY; - if (type == "cname") + if (type.compare(u"cname", Qt::CaseInsensitive) == 0) return QDnsLookup::CNAME; - if (type == "mx") + if (type.compare(u"mx", Qt::CaseInsensitive) == 0) return QDnsLookup::MX; - if (type == "ns") + if (type.compare(u"ns", Qt::CaseInsensitive) == 0) return QDnsLookup::NS; - if (type == "ptr") + if (type.compare(u"ptr", Qt::CaseInsensitive) == 0) return QDnsLookup::PTR; - if (type == "srv") + if (type.compare(u"srv", Qt::CaseInsensitive) == 0) return QDnsLookup::SRV; - if (type == "txt") + if (type.compare(u"txt", Qt::CaseInsensitive) == 0) return QDnsLookup::TXT; return -1; } @@ -79,7 +79,7 @@ CommandLineParseResult parseCommandLine(QCommandLineParser &parser, DnsQuery *qu if (parser.isSet(typeOption)) { const QString typeParameter = parser.value(typeOption); - const int type = typeFromParameter(typeParameter.toLower()); + const int type = typeFromParameter(typeParameter); if (type < 0) { *errorMessage = "Bad record type: " + typeParameter; return CommandLineError;