From d36ea4d76951b441d9cc91e01d6dcbd17ad78b6e Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sun, 9 Feb 2025 00:34:15 +0100 Subject: [PATCH] ImGui: strong optimizations for color logger Don't recalculate the length of each text on the lines displayed when pushing it to the draw list. Also use the already calculated length for intermediate operations. --- src/thirdparty/imgui/misc/imgui_logger.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/thirdparty/imgui/misc/imgui_logger.cpp b/src/thirdparty/imgui/misc/imgui_logger.cpp index 88696a26..734e77f7 100644 --- a/src/thirdparty/imgui/misc/imgui_logger.cpp +++ b/src/thirdparty/imgui/misc/imgui_logger.cpp @@ -340,7 +340,7 @@ CTextLogger::Coordinates CTextLogger::ScreenPosToCoordinates(const ImVec2& aPosi buf[i++] = line.buffer[columnIndex++]; buf[i] = '\0'; - columnWidth = ImGui::GetFont()->CalcTextSizeA(ImGui::GetFontSize(), FLT_MAX, -1.0f, buf).x; + columnWidth = ImGui::GetFont()->CalcTextSizeA(ImGui::GetFontSize(), FLT_MAX, -1.0f, buf, &buf[i]).x; if (columnX + columnWidth * 0.5f > local.x) break; @@ -859,17 +859,20 @@ void CTextLogger::Render() if (!line.buffer.empty()) { + const char* const text = line.buffer.c_str(); + const char* const textEnd = &text[line.buffer.length()]; + ImU32 color = line.color; if (m_itFilter.IsActive()) { // Make line dark if it isn't found by the filter - if (!m_itFilter.PassFilter(line.buffer.c_str())) + if (!m_itFilter.PassFilter(text, textEnd)) color = 0xff605040; } const ImVec2 newOffset(textScreenPos.x, textScreenPos.y); - drawList->AddText(newOffset, color, line.buffer.c_str()); + drawList->AddText(newOffset, color, text, textEnd); } ++lineNo; @@ -1485,7 +1488,7 @@ float CTextLogger::TextDistanceToLineStart(const Coordinates& aFrom) const tempCString[i] = line.buffer[it]; tempCString[i] = '\0'; - distance += ImGui::GetFont()->CalcTextSizeA(ImGui::GetFontSize(), FLT_MAX, -1.0f, tempCString, nullptr, nullptr).x; + distance += ImGui::GetFont()->CalcTextSizeA(ImGui::GetFontSize(), FLT_MAX, -1.0f, tempCString, &tempCString[i], nullptr).x; } }