Add list is empty judgment,optimize to use constant

the last() method of the mPendingTouchPoints list is judged to be empty before it is called, and the last() is optimised to constLast() according to the logic below.

Change-Id: I8ec082a22c223d06dbe848bc70622710b6acfa50
Reviewed-by: Feifei Zhan <noone@onqt.com>
Reviewed-by: David Edmundson <davidedmundson@kde.org>
This commit is contained in:
Feifei Zhan 2023-10-12 10:52:07 +08:00
parent e73979a94f
commit 792f1915fc

View File

@ -1548,7 +1548,12 @@ void QWaylandInputDevice::Touch::touch_frame()
QWindow *window = mFocus ? mFocus->window() : nullptr;
if (mFocus) {
const QWindowSystemInterface::TouchPoint &tp = mPendingTouchPoints.last();
// Returns a reference to the last item in the list. The list must not be empty.
// If the list can be empty, call isEmpty() before calling this function.
// See: https://doc.qt.io/qt-5.15/qlist.html#last
if (mPendingTouchPoints.empty())
return;
const QWindowSystemInterface::TouchPoint &tp = mPendingTouchPoints.constLast();
// When the touch event is received, the global pos is calculated with the margins
// in mind. Now we need to adjust again to get the correct local pos back.
QMargins margins = window->frameMargins();