From e2c87e22701a261d8415e6f7a15a14d2ae3c03a5 Mon Sep 17 00:00:00 2001 From: Inho Lee Date: Fri, 2 Feb 2024 12:36:08 +0100 Subject: Remove redundant calls, textInput() It is used repeatedly. Normally it can be optimized by a compiler but it might be helpful to see what it is by the name, inputInterface. Pick-to: 6.7 6.6 6.5 Change-Id: I7f4988674d7249c84b1321e69146dfd92189f142 Reviewed-by: David Edmundson --- src/client/qwaylandinputcontext.cpp | 63 ++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 26 deletions(-) (limited to 'src/client/qwaylandinputcontext.cpp') diff --git a/src/client/qwaylandinputcontext.cpp b/src/client/qwaylandinputcontext.cpp index 4b6a34c6b..a38bb9a0a 100644 --- a/src/client/qwaylandinputcontext.cpp +++ b/src/client/qwaylandinputcontext.cpp @@ -48,20 +48,22 @@ void QWaylandInputContext::reset() QPlatformInputContext::reset(); - if (!textInput()) + QWaylandTextInputInterface *inputInterface = textInput(); + if (!inputInterface) return; - textInput()->reset(); + inputInterface->reset(); } void QWaylandInputContext::commit() { qCDebug(qLcQpaInputMethods) << Q_FUNC_INFO; - if (!textInput()) + QWaylandTextInputInterface *inputInterface = textInput(); + if (!inputInterface) return; - textInput()->commit(); + inputInterface->commit(); } static ::wl_surface *surfaceForWindow(QWindow *window) @@ -77,92 +79,100 @@ void QWaylandInputContext::update(Qt::InputMethodQueries queries) { qCDebug(qLcQpaInputMethods) << Q_FUNC_INFO << queries; - if (!QGuiApplication::focusObject() || !textInput()) + QWaylandTextInputInterface *inputInterface = textInput(); + if (!QGuiApplication::focusObject() || !inputInterface) return; auto *currentSurface = surfaceForWindow(mCurrentWindow); if (currentSurface && !inputMethodAccepted()) { - textInput()->disableSurface(currentSurface); + inputInterface->disableSurface(currentSurface); mCurrentWindow.clear(); } else if (!currentSurface && inputMethodAccepted()) { QWindow *window = QGuiApplication::focusWindow(); if (auto *focusSurface = surfaceForWindow(window)) { - textInput()->enableSurface(focusSurface); + inputInterface->enableSurface(focusSurface); mCurrentWindow = window; } } - textInput()->updateState(queries, QWaylandTextInputInterface::update_state_change); + inputInterface->updateState(queries, QWaylandTextInputInterface::update_state_change); } void QWaylandInputContext::invokeAction(QInputMethod::Action action, int cursorPostion) { - if (!textInput()) + QWaylandTextInputInterface *inputInterface = textInput(); + if (!inputInterface) return; if (action == QInputMethod::Click) - textInput()->setCursorInsidePreedit(cursorPostion); + inputInterface->setCursorInsidePreedit(cursorPostion); } void QWaylandInputContext::showInputPanel() { qCDebug(qLcQpaInputMethods) << Q_FUNC_INFO; - if (!textInput()) + QWaylandTextInputInterface *inputInterface = textInput(); + if (!inputInterface) return; - textInput()->showInputPanel(); + inputInterface->showInputPanel(); } void QWaylandInputContext::hideInputPanel() { qCDebug(qLcQpaInputMethods) << Q_FUNC_INFO; - if (!textInput()) + QWaylandTextInputInterface *inputInterface = textInput(); + if (!inputInterface) return; - textInput()->hideInputPanel(); + inputInterface->hideInputPanel(); } bool QWaylandInputContext::isInputPanelVisible() const { qCDebug(qLcQpaInputMethods) << Q_FUNC_INFO; - if (!textInput()) + QWaylandTextInputInterface *inputInterface = textInput(); + if (!inputInterface) return QPlatformInputContext::isInputPanelVisible(); - return textInput()->isInputPanelVisible(); + return inputInterface->isInputPanelVisible(); } QRectF QWaylandInputContext::keyboardRect() const { qCDebug(qLcQpaInputMethods) << Q_FUNC_INFO; - if (!textInput()) + QWaylandTextInputInterface *inputInterface = textInput(); + if (!inputInterface) return QPlatformInputContext::keyboardRect(); - return textInput()->keyboardRect(); + return inputInterface->keyboardRect(); } QLocale QWaylandInputContext::locale() const { qCDebug(qLcQpaInputMethods) << Q_FUNC_INFO; - if (!textInput()) + QWaylandTextInputInterface *inputInterface = textInput(); + if (!inputInterface) return QPlatformInputContext::locale(); - return textInput()->locale(); + return inputInterface->locale(); } Qt::LayoutDirection QWaylandInputContext::inputDirection() const { qCDebug(qLcQpaInputMethods) << Q_FUNC_INFO; - if (!textInput()) + QWaylandTextInputInterface *inputInterface = textInput(); + if (!inputInterface) return QPlatformInputContext::inputDirection(); - return textInput()->inputDirection(); + return inputInterface->inputDirection(); } void QWaylandInputContext::setFocusObject(QObject *object) @@ -174,7 +184,8 @@ void QWaylandInputContext::setFocusObject(QObject *object) Q_UNUSED(object); #endif - if (!textInput()) + QWaylandTextInputInterface *inputInterface = textInput(); + if (!inputInterface) return; QWindow *window = QGuiApplication::focusWindow(); @@ -183,7 +194,7 @@ void QWaylandInputContext::setFocusObject(QObject *object) if (mCurrentWindow.data() != window || !inputMethodAccepted()) { auto *surface = static_cast(mCurrentWindow->handle())->wlSurface(); if (surface) - textInput()->disableSurface(surface); + inputInterface->disableSurface(surface); mCurrentWindow.clear(); } } @@ -192,11 +203,11 @@ void QWaylandInputContext::setFocusObject(QObject *object) if (mCurrentWindow.data() != window) { auto *surface = static_cast(window->handle())->wlSurface(); if (surface) { - textInput()->enableSurface(surface); + inputInterface->enableSurface(surface); mCurrentWindow = window; } } - textInput()->updateState(Qt::ImQueryAll, QWaylandTextInputInterface::update_state_enter); + inputInterface->updateState(Qt::ImQueryAll, QWaylandTextInputInterface::update_state_enter); } } -- cgit v1.2.3