diff options
author | Mårten Nordheim <marten.nordheim@qt.io> | 2023-02-27 17:36:01 +0100 |
---|---|---|
committer | Mårten Nordheim <marten.nordheim@qt.io> | 2023-03-02 12:08:09 +0100 |
commit | 5e16397a2cabd963c183a722c6daff6b2a32eada (patch) | |
tree | b94ead16d04b9233c5e0adad2a5ef63e27d79e1b /examples | |
parent | eb61d49ab3a4f4d9dae3ccfdaf416190fb168c27 (diff) |
DNS Lookup: Avoid unneeded allocations in parsing function
By using .compare(~~~, Qt::CaseInsensitive) instead of .toLower()
Task-number: QTBUG-108873
Pick-to: 6.5
Change-Id: I60e1fdc0a54450e7385e90f84fd509e62b82d2c9
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/network/dnslookup/dnslookup.cpp | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/examples/network/dnslookup/dnslookup.cpp b/examples/network/dnslookup/dnslookup.cpp index c0f593563c..84afeaaf02 100644 --- a/examples/network/dnslookup/dnslookup.cpp +++ b/examples/network/dnslookup/dnslookup.cpp @@ -13,25 +13,25 @@ #include <stdio.h> -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; |