From 9c3434c4e73c8ee8d20243d28d5806366159ce75 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 27 Oct 2022 14:51:15 -0700 Subject: [PATCH] QLocale: remove unwise early return in bytearrayTo(Uns)LongLong Optimize the code for non-empty strings, which are the vast majority of the conversions. Plus, qstrnto(u)ll operate just fine on empty strings. This saves 4 instrctions per call on my laptop for any non-empty input, and up to 4 cycles of execution. Change-Id: I07ec23f3cb174fb197c3fffd17220b846a026b55 Reviewed-by: Edward Welbourne (cherry picked from commit 826dc56d3a941447d02fad48a47441f2329af0bf) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/text/qlocale.cpp | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index 7734e694221..c29d4d745c4 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -4116,12 +4116,6 @@ qulonglong QLocaleData::stringToUnsLongLong(QStringView str, int base, bool *ok, qlonglong QLocaleData::bytearrayToLongLong(QByteArrayView num, int base, bool *ok) { - if (num.isEmpty() || num.at(0) == '\0') { - if (ok != nullptr) - *ok = false; - return 0; - } - bool _ok; const char *endptr; const qlonglong l = qstrntoll(num.data(), num.size(), &endptr, base, &_ok); @@ -4152,12 +4146,6 @@ qlonglong QLocaleData::bytearrayToLongLong(QByteArrayView num, int base, bool *o qulonglong QLocaleData::bytearrayToUnsLongLong(QByteArrayView num, int base, bool *ok) { - if (num.isEmpty() || num.at(0) == '\0') { - if (ok != nullptr) - *ok = false; - return 0; - } - bool _ok; const char *endptr; const qulonglong l = qstrntoull(num.data(), num.size(), &endptr, base, &_ok);