From 885ae61c6378e06a965f543d2ecbd162c6224347 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 27 Oct 2022 12:36:37 -0700 Subject: [PATCH] QString: skip QLocale::numberToCLocale for C locale inputs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QString inputs are required to be in the C locale, so we can simply use qt_to_latin1() in qstring.cpp to do the conversion from UTF-16 to US- ASCII. There's no need to operate on QLocaleData. Benchmark of QString::toInt() on "42"; before: 152.8176 ns task-clock:u # 0.999 CPUs utilized 425.904 cycles:u # 2.787 GHz 1550.992 instructions:u # 3.64 insn per cycle 363.998 branches:u # 2.382 G/sec Now, with a slightly optimized qt_to_latin1: 19.3383 ns task-clock 54.005 cycles:u # 2.793 GHz 238.000 instructions:u # 4.407 insn per cycle 55.000 branches:u # 2.844 G/sec And with AVX512 256-bit qt_to_latin1: 20.6798 ns task-clock 57.748 cycles:u # 2.793 GHz 237.000 instructions:u # 4.104 insn per cycle 50.000 branches:u # 2.418 G/sec For comparison, a QByteArray::toInt() on "42" produces: 17.2310 ns task-clock 48.081 cycles:u # 2.790 GHz 205.000 instructions:u # 4.264 insn per cycle 49.000 branches:u # 2.844 G/sec Fixes: QTBUG-107788 Pick-to: 6.4 Change-Id: I07ec23f3cb174fb197c3fffd1722042b9ccbacbf Reviewed-by: Edward Welbourne Reviewed-by: MÃ¥rten Nordheim --- src/corelib/text/qstring.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index 79ab557e81..cbaa9a4c36 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -7185,7 +7185,9 @@ qlonglong QString::toIntegral_helper(QStringView string, bool *ok, int base) } #endif - return QLocaleData::c()->stringToLongLong(string, base, ok, QLocale::RejectGroupSeparator); + QVarLengthArray latin1(string.size()); + qt_to_latin1(latin1.data(), string.utf16(), string.size()); + return QLocaleData::bytearrayToLongLong(latin1, base, ok); } @@ -7230,7 +7232,9 @@ qulonglong QString::toIntegral_helper(QStringView string, bool *ok, uint base) } #endif - return QLocaleData::c()->stringToUnsLongLong(string, base, ok, QLocale::RejectGroupSeparator); + QVarLengthArray latin1(string.size()); + qt_to_latin1(latin1.data(), string.utf16(), string.size()); + return QLocaleData::bytearrayToUnsLongLong(latin1, base, ok); } /*!