From ad4e7c33552bdd06edb08da1fff38cf2f38e6082 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Wed, 8 Nov 2023 12:46:47 +0100 Subject: [PATCH] impr: Don't check for overflow every frame --- .../builtin/source/content/tools_entries.cpp | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/plugins/builtin/source/content/tools_entries.cpp b/plugins/builtin/source/content/tools_entries.cpp index dafc7fc27..50f178c93 100644 --- a/plugins/builtin/source/content/tools_entries.cpp +++ b/plugins/builtin/source/content/tools_entries.cpp @@ -2102,23 +2102,25 @@ namespace hex::plugin::builtin { hasChanged = ImGui::InputScalar("A", ImGuiDataType_U64, &a) || hasChanged; hasChanged = ImGui::InputScalar("B", ImGuiDataType_U64, &b) || hasChanged; - // Detect overflow - const u64 multiplicationResult = a * b; - if (a != 0 && multiplicationResult / a != b) { - gcdResult = 0; - lcmResult = 0; - p = 0; - q = 0; + // Update results when input changed + if (hasChanged) { - overflow = true; - } else { - if (hasChanged) { + // Detect overflow + const u64 multiplicationResult = a * b; + if (a != 0 && multiplicationResult / a != b) { + gcdResult = 0; + lcmResult = 0; + p = 0; + q = 0; + + overflow = true; + } else { gcdResult = std::gcd(a, b); lcmResult = std::lcm(a, b); std::tie(p, q) = extendedGcd(a, b); - } - overflow = false; + overflow = false; + } } ImGui::Separator();