QString: skip QLocale::numberToCLocale for C locale inputs
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 Change-Id: I07ec23f3cb174fb197c3fffd1722042b9ccbacbf Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> (cherry picked from commit 885ae61c6378e06a965f543d2ecbd162c6224347) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
43f9f953bc
commit
31e4d6403c
@ -7109,7 +7109,9 @@ qlonglong QString::toIntegral_helper(QStringView string, bool *ok, int base)
|
||||
}
|
||||
#endif
|
||||
|
||||
return QLocaleData::c()->stringToLongLong(string, base, ok, QLocale::RejectGroupSeparator);
|
||||
QVarLengthArray<uchar> latin1(string.size());
|
||||
qt_to_latin1(latin1.data(), string.utf16(), string.size());
|
||||
return QLocaleData::bytearrayToLongLong(latin1, base, ok);
|
||||
}
|
||||
|
||||
|
||||
@ -7154,7 +7156,9 @@ qulonglong QString::toIntegral_helper(QStringView string, bool *ok, uint base)
|
||||
}
|
||||
#endif
|
||||
|
||||
return QLocaleData::c()->stringToUnsLongLong(string, base, ok, QLocale::RejectGroupSeparator);
|
||||
QVarLengthArray<uchar> latin1(string.size());
|
||||
qt_to_latin1(latin1.data(), string.utf16(), string.size());
|
||||
return QLocaleData::bytearrayToUnsLongLong(latin1, base, ok);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
Loading…
x
Reference in New Issue
Block a user