diff options
| author | Marc Mutz <marc.mutz@qt.io> | 2025-10-14 10:36:25 +0200 |
|---|---|---|
| committer | Marc Mutz <marc.mutz@qt.io> | 2025-10-15 16:51:11 +0200 |
| commit | 956f7a94566d3ddb63d79d49ad047ec1a6ab03cc (patch) | |
| tree | 834edaf3d6089456fbe0e5b0cb06fa23c33d4199 /src/gui/util/qundostack.cpp | |
| parent | 9b4c15ef5ffa94829a0c690eba37472c6833600c (diff) | |
QUndoStack: fix two Coverity COPY_INSTEAD_OF_MOVE warnings
Coverity complained that, since the ActionState struct contains a
QString, a copy is expensive while a move is possible.
Make it so.
To avoid explicit std::move() far away from the end of the scope
(which impairs readability), use C++17 if-with-initializer to reduce
the scope of the newX ActionState objects. This is a drive-by, since
to move from them, we need to de-const the variables, anyway.
Amends 31b0dadb0f371fc94652782c28024f135a0b6f4b.
Pick-to: 6.10 6.8
Coverity-Id: 896353
Coverity-Id: 896351
Task-number: QTBUG-138567
Change-Id: Id365d9bd91773452d16634a3b862f3d23ad650b9
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Reviewed-by: Ali Kianian <ali.kianian@qt.io>
Diffstat (limited to 'src/gui/util/qundostack.cpp')
| -rw-r--r-- | src/gui/util/qundostack.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/gui/util/qundostack.cpp b/src/gui/util/qundostack.cpp index 3d1d8a2b788..27b131cd733 100644 --- a/src/gui/util/qundostack.cpp +++ b/src/gui/util/qundostack.cpp @@ -425,16 +425,16 @@ void QUndoStackPrivate::setIndex(int idx, bool clean) emit q->indexChanged(index); } - const ActionState newUndoState{q->canUndo(), q->undoText()}; - if (indexChanged || newUndoState != undoActionState) { - undoActionState = newUndoState; + if (ActionState newUndoState{q->canUndo(), q->undoText()}; + indexChanged || newUndoState != undoActionState) { + undoActionState = std::move(newUndoState); emit q->canUndoChanged(undoActionState.enabled); emit q->undoTextChanged(undoActionState.text); } - const ActionState newRedoState{q->canRedo(), q->redoText()}; - if (indexChanged || newRedoState != redoActionState) { - redoActionState = newRedoState; + if (ActionState newRedoState{q->canRedo(), q->redoText()}; + indexChanged || newRedoState != redoActionState) { + redoActionState = std::move(newRedoState); emit q->canRedoChanged(redoActionState.enabled); emit q->redoTextChanged(redoActionState.text); } |
