From 792f1915fcb5232118f86644e9c7b06a12000d3b Mon Sep 17 00:00:00 2001 From: Feifei Zhan Date: Thu, 12 Oct 2023 10:52:07 +0800 Subject: [PATCH] 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 Reviewed-by: David Edmundson --- src/plugins/platforms/wayland/qwaylandinputdevice.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/plugins/platforms/wayland/qwaylandinputdevice.cpp b/src/plugins/platforms/wayland/qwaylandinputdevice.cpp index f26595708ea..aa11823ba3b 100644 --- a/src/plugins/platforms/wayland/qwaylandinputdevice.cpp +++ b/src/plugins/platforms/wayland/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();