From 59928d23fc22d916dea32f02d810b8b24b74922d Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 30 Jan 2017 15:25:23 +0100 Subject: Port QLocalePrivate::*ToCode() to QLatin1String The returned data is in US-ASCII (or else Latin-1), and resides in consecutive memory. We can therefore return it in a QLatin1String, which, however, will in general not be NUL-terminated. Many users use the return value as part of a QStringBuilder expression, and those which are not are not pessimized further by this change. The caller in qtimezoneprivate_icu looks as if it could simply zero -terminate the return value and use it as-is, as opposed to converting to UTF-8, but I left the code equivalent to the original just the same. Change-Id: I0e628af8c1320fcff8d0aacf160e859681d2b85a Reviewed-by: Edward Welbourne Reviewed-by: Thiago Macieira --- src/corelib/tools/qtimezoneprivate_icu.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/corelib/tools/qtimezoneprivate_icu.cpp') diff --git a/src/corelib/tools/qtimezoneprivate_icu.cpp b/src/corelib/tools/qtimezoneprivate_icu.cpp index 887486f567..a07b2593b9 100644 --- a/src/corelib/tools/qtimezoneprivate_icu.cpp +++ b/src/corelib/tools/qtimezoneprivate_icu.cpp @@ -477,9 +477,10 @@ QList QIcuTimeZonePrivate::availableTimeZoneIds() const QList QIcuTimeZonePrivate::availableTimeZoneIds(QLocale::Country country) const { - QByteArray regionCode = QLocalePrivate::countryToCode(country).toUtf8(); + const QLatin1String regionCode = QLocalePrivate::countryToCode(country); + const QByteArray regionCodeUtf8 = QString(regionCode).toUtf8(); UErrorCode status = U_ZERO_ERROR; - UEnumeration *uenum = ucal_openCountryTimeZones(regionCode, &status); + UEnumeration *uenum = ucal_openCountryTimeZones(regionCodeUtf8.data(), &status); QList result; if (U_SUCCESS(status)) result = uenumToIdList(uenum); -- cgit v1.2.3