From e2309e5c48f822a7514afbebbb708ac1ed054bbc Mon Sep 17 00:00:00 2001 From: Ievgenii Meshcheriakov Date: Thu, 22 Jul 2021 14:28:30 +0200 Subject: 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 Reviewed-by: Edward Welbourne Reviewed-by: Lars Knoll (cherry picked from commit 25170b324b7db872be2a2bde5c04eb0c1e3972e5) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/time/qcalendar.cpp | 16 +--------------- src/corelib/time/qcalendar.h | 2 ++ src/corelib/time/qcalendarbackend_p.h | 4 ++-- 3 files changed, 5 insertions(+), 17 deletions(-) diff --git a/src/corelib/time/qcalendar.cpp b/src/corelib/time/qcalendar.cpp index 4a245f6d3f..d3dada33b3 100644 --- a/src/corelib/time/qcalendar.cpp +++ b/src/corelib/time/qcalendar.cpp @@ -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. diff --git a/src/corelib/time/qcalendar.h b/src/corelib/time/qcalendar.h index c3d8800db8..a723209a1c 100644 --- a/src/corelib/time/qcalendar.h +++ b/src/corelib/time/qcalendar.h @@ -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); diff --git a/src/corelib/time/qcalendarbackend_p.h b/src/corelib/time/qcalendarbackend_p.h index c3f57e7f74..83893571fc 100644 --- a/src/corelib/time/qcalendarbackend_p.h +++ b/src/corelib/time/qcalendarbackend_p.h @@ -56,6 +56,7 @@ #include #include #include +#include #include 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); -- cgit v1.2.3