Skip to content

Commit

Permalink
QCalendar: Optimize std::vector access
Browse files Browse the repository at this point in the history
As we assert on the size of the vector before accessing it, there is no
point in using the checked at() method over operator[]. Besides, if at()
throws, what are we going to do with the exception anyway.

Incidentally, this also works around a compiler bug causing binary
incompatibility in QtQml.

Change-Id: I460e7514429daecabc304eb2c5f96ed715008b0a
Fixes: QTBUG-80535
Reviewed-by: Volker Hilsheimer <[email protected]>
  • Loading branch information
Ulf Hermann committed Dec 7, 2019
1 parent 61f92c0 commit 2a887a5
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/corelib/time/qcalendar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ struct Registry {
if (id == QCalendar::System::User) {
byId.push_back(calendar);
} else {
Q_ASSERT(byId.at(size_t(id)) == nullptr);
Q_ASSERT(byId[size_t(id)] == nullptr);
byId[size_t(id)] = calendar;
}
if (id == QCalendar::System::Gregorian) {
Expand Down Expand Up @@ -618,7 +618,7 @@ const QCalendarBackend *QCalendarBackend::fromEnum(QCalendar::System system)
if (calendarRegistry.isDestroyed() || system == QCalendar::System::User)
return nullptr;
Q_ASSERT(calendarRegistry->byId.size() >= size_t(system));
if (auto *c = calendarRegistry->byId.at(size_t(system)))
if (auto *c = calendarRegistry->byId[size_t(system)])
return c;
switch (system) {
case QCalendar::System::Gregorian:
Expand Down

0 comments on commit 2a887a5

Please sign in to comment.