From 4509bc385b56d758326e62a213730842287de7a9 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Thu, 20 Oct 2022 15:22:20 +0200 Subject: [PATCH] CConsole::SuggestPanel inprovements * Cache m_vSuggest.size(). * Use const reference to m_vSuggest[i]. --- r5dev/gameui/IConsole.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/r5dev/gameui/IConsole.cpp b/r5dev/gameui/IConsole.cpp index af3fbe54..493b59cc 100644 --- a/r5dev/gameui/IConsole.cpp +++ b/r5dev/gameui/IConsole.cpp @@ -359,24 +359,26 @@ void CConsole::SuggestPanel(void) ImGui::Begin("##suggest", nullptr, m_nSuggestFlags); ImGui::PushAllowKeyboardFocus(false); - for (size_t i = 0; i < m_vSuggest.size(); i++) + for (size_t i = 0, ns = m_vSuggest.size(); i < ns; i++) { + const CSuggest& suggest = m_vSuggest[i]; const bool bIsIndexActive = m_nSuggestPos == i; + ImGui::PushID(static_cast(i)); if (con_suggestion_showflags->GetBool()) { - const int k = GetFlagColorIndex(m_vSuggest[i].m_nFlags); + const int k = GetFlagColorIndex(suggest.m_nFlags); ImGui::Image(m_vFlagIcons[k].m_idIcon, ImVec2(m_vFlagIcons[k].m_nWidth, m_vFlagIcons[k].m_nHeight)); ImGui::SameLine(); } - if (ImGui::Selectable(m_vSuggest[i].m_svName.c_str(), bIsIndexActive)) + if (ImGui::Selectable(suggest.m_svName.c_str(), bIsIndexActive)) { ImGui::Separator(); // Remove the default value from ConVar before assigning it to the input buffer. - const string svConVar = m_vSuggest[i].m_svName.substr(0, m_vSuggest[i].m_svName.find(' ')) + ' '; + const string svConVar = suggest.m_svName.substr(0, suggest.m_svName.find(' ')) + ' '; memmove(m_szInputBuf, svConVar.data(), svConVar.size() + 1); ResetAutoComplete();