QCalendarBackend: Use QAnyStringView to create backends by name

Combine two implementations of QCalendarBackend::byName() accepting
QStringView and QLatin1String arguments into one accepting
QAnyStringView to reduce code duplication.

Add a note to QCalendar constructors accepting strings to do the
same for Qt 7.

Change-Id: Idfc3b9c61e22712543c723bd94fcd788da52780a
Pick-to: 6.2
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
bb10
Ievgenii Meshcheriakov 2021-07-22 14:28:30 +02:00
parent 7d49dc2222
commit 25170b324b
3 changed files with 5 additions and 17 deletions

View File

@ -890,7 +890,7 @@ bool QCalendarBackend::registerAlias(const QString &name)
\sa availableCalendars(), registerAlias(), fromEnum(), fromId()
*/
const QCalendarBackend *QCalendarBackend::fromName(QStringView name)
const QCalendarBackend *QCalendarBackend::fromName(QAnyStringView name)
{
if (calendarRegistry.isDestroyed())
return nullptr;
@ -900,20 +900,6 @@ const QCalendarBackend *QCalendarBackend::fromName(QStringView name)
return it == calendarRegistry->byName.end() ? nullptr : *it;
}
/*!
\internal
\overload
*/
const QCalendarBackend *QCalendarBackend::fromName(QLatin1String name)
{
if (calendarRegistry.isDestroyed())
return nullptr;
calendarRegistry->populate();
const auto registryLock = qt_scoped_lock(registryMutex);
auto it = calendarRegistry->byName.find(QString(name));
return it == calendarRegistry->byName.end() ? nullptr : *it;
}
/*!
\internal
Returns a pointer to a calendar backend, specified by ID.

View File

@ -145,7 +145,9 @@ public:
explicit QCalendar(); // Gregorian, optimised
explicit QCalendar(System system);
// ### Qt 7: remove
explicit QCalendar(QLatin1String name);
// ### Qt 7: use QAnyStringView
explicit QCalendar(QStringView name);
explicit QCalendar(SystemId id);

View File

@ -56,6 +56,7 @@
#include <QtCore/qstringlist.h>
#include <QtCore/qstring.h>
#include <QtCore/qmap.h>
#include <QtCore/qanystringview.h>
#include <QtCore/private/qlocale_p.h>
QT_BEGIN_NAMESPACE
@ -145,8 +146,7 @@ protected:
private:
const QCalendar::SystemId m_id;
// QCalendar's access to its registry:
static const QCalendarBackend *fromName(QStringView name);
static const QCalendarBackend *fromName(QLatin1String name);
static const QCalendarBackend *fromName(QAnyStringView name);
static const QCalendarBackend *fromId(QCalendar::SystemId id);
// QCalendar's access to singletons:
static const QCalendarBackend *fromEnum(QCalendar::System system);