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
Pick-to: 6.4
Change-Id: I07ec23f3cb174fb197c3fffd1722042b9ccbacbf
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
bb10
Thiago Macieira 2022-10-27 12:36:37 -07:00
parent f0a7d74e1d
commit 885ae61c63
1 changed files with 6 additions and 2 deletions

View File

@ -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<uchar> 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<uchar> latin1(string.size());
qt_to_latin1(latin1.data(), string.utf16(), string.size());
return QLocaleData::bytearrayToUnsLongLong(latin1, base, ok);
}
/*!