From 7dc0bdd5dfaa7aa8f6902126c1e05b0ee23d45a9 Mon Sep 17 00:00:00 2001 From: mitaclaw <140017135+mitaclaw@users.noreply.github.com> Date: Fri, 24 May 2024 17:05:14 -0700 Subject: [PATCH 1/2] BranchWatchProxyModel: Avoid String Copies In filterAcceptsRow --- Source/Core/DolphinQt/Debugger/BranchWatchDialog.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Core/DolphinQt/Debugger/BranchWatchDialog.cpp b/Source/Core/DolphinQt/Debugger/BranchWatchDialog.cpp index c20b2e3c2d..e6c3e7341e 100644 --- a/Source/Core/DolphinQt/Debugger/BranchWatchDialog.cpp +++ b/Source/Core/DolphinQt/Debugger/BranchWatchDialog.cpp @@ -141,15 +141,15 @@ bool BranchWatchProxyModel::filterAcceptsRow(int source_row, const QModelIndex&) if (!m_origin_symbol_name.isEmpty()) { if (const QVariant& symbol_name_v = sourceModel()->GetSymbolList()[source_row].origin_name; - !symbol_name_v.isValid() || - !symbol_name_v.value().contains(m_origin_symbol_name, Qt::CaseInsensitive)) + !symbol_name_v.isValid() || !static_cast(symbol_name_v.data()) + ->contains(m_origin_symbol_name, Qt::CaseInsensitive)) return false; } if (!m_destin_symbol_name.isEmpty()) { if (const QVariant& symbol_name_v = sourceModel()->GetSymbolList()[source_row].destin_name; - !symbol_name_v.isValid() || - !symbol_name_v.value().contains(m_destin_symbol_name, Qt::CaseInsensitive)) + !symbol_name_v.isValid() || !static_cast(symbol_name_v.data()) + ->contains(m_destin_symbol_name, Qt::CaseInsensitive)) return false; } return true; From 8050760fe928db8a3f7eed25c5e4372af6f2bc24 Mon Sep 17 00:00:00 2001 From: mitaclaw <140017135+mitaclaw@users.noreply.github.com> Date: Fri, 24 May 2024 17:47:25 -0700 Subject: [PATCH 2/2] BranchWatchTableModel: Assume Unreachable Code Truly Is --- Source/Core/Common/CMakeLists.txt | 1 + Source/Core/Common/Unreachable.h | 21 +++++++++++++++++++ Source/Core/DolphinLib.props | 1 + .../Debugger/BranchWatchTableModel.cpp | 10 ++++++--- 4 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 Source/Core/Common/Unreachable.h diff --git a/Source/Core/Common/CMakeLists.txt b/Source/Core/Common/CMakeLists.txt index af48ba7e13..fd2b04a721 100644 --- a/Source/Core/Common/CMakeLists.txt +++ b/Source/Core/Common/CMakeLists.txt @@ -143,6 +143,7 @@ add_library(common TraversalClient.h TraversalProto.h TypeUtils.h + Unreachable.h UPnP.cpp UPnP.h VariantUtil.h diff --git a/Source/Core/Common/Unreachable.h b/Source/Core/Common/Unreachable.h new file mode 100644 index 0000000000..a01810a239 --- /dev/null +++ b/Source/Core/Common/Unreachable.h @@ -0,0 +1,21 @@ +// Copyright 2024 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "Common/CommonFuncs.h" + +namespace Common +{ +// TODO C++23: Replace with std::unreachable. +[[noreturn]] inline void Unreachable() +{ +#ifdef _DEBUG + Crash(); +#elif defined(_MSC_VER) && !defined(__clang__) + __assume(false); +#else + __builtin_unreachable(); +#endif +} +} // namespace Common diff --git a/Source/Core/DolphinLib.props b/Source/Core/DolphinLib.props index beec3e9a2d..56484070d0 100644 --- a/Source/Core/DolphinLib.props +++ b/Source/Core/DolphinLib.props @@ -165,6 +165,7 @@ + diff --git a/Source/Core/DolphinQt/Debugger/BranchWatchTableModel.cpp b/Source/Core/DolphinQt/Debugger/BranchWatchTableModel.cpp index 08d7ae021d..e4d8dd21a2 100644 --- a/Source/Core/DolphinQt/Debugger/BranchWatchTableModel.cpp +++ b/Source/Core/DolphinQt/Debugger/BranchWatchTableModel.cpp @@ -11,6 +11,7 @@ #include "Common/Assert.h" #include "Common/GekkoDisassembler.h" +#include "Common/Unreachable.h" #include "Core/Debugger/BranchWatch.h" #include "Core/PowerPC/PPCSymbolDB.h" @@ -355,7 +356,8 @@ QVariant BranchWatchTableModel::DisplayRoleData(const QModelIndex& index) const case Column::TotalHits: return QString::number(kv->second.total_hits); } - return QVariant(); + static_assert(Column::NumberOfColumns == 8); + Common::Unreachable(); } QVariant BranchWatchTableModel::FontRoleData(const QModelIndex& index) const @@ -400,7 +402,8 @@ QVariant BranchWatchTableModel::TextAlignmentRoleData(const QModelIndex& index) case Column::DestinSymbol: return QVariant::fromValue(Qt::AlignLeft | Qt::AlignVCenter); } - return QVariant(); + static_assert(Column::NumberOfColumns == 8); + Common::Unreachable(); } QVariant BranchWatchTableModel::ForegroundRoleData(const QModelIndex& index) const @@ -498,5 +501,6 @@ QVariant BranchWatchTableModel::SortRoleData(const QModelIndex& index) const case Column::TotalHits: return qulonglong{kv->second.total_hits}; } - return QVariant(); + static_assert(Column::NumberOfColumns == 8); + Common::Unreachable(); }