summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFeifei Zhan <noone@onqt.com>2023-10-12 10:52:07 +0800
committerFeifei Zhan <noone@onqt.com>2023-11-03 02:57:19 +0000
commitbb39f2dc6b0aeb29e1b671fdf67eaddfa538fd1f (patch)
treefe829a44c8e7706f647098e22a728d50aaa434a2 /src
parentc22eeb63f8d2a202e1ed6b8674e09836c2bffdeb (diff)
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>
Diffstat (limited to 'src')
-rw-r--r--src/client/qwaylandinputdevice.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/client/qwaylandinputdevice.cpp b/src/client/qwaylandinputdevice.cpp
index f26595708..aa11823ba 100644
--- a/src/client/qwaylandinputdevice.cpp
+++ b/src/client/qwaylandinputdevice.cpp
@@ -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();