From a42c8587cbad2c81f1dce41042c956ce7adef8cb Mon Sep 17 00:00:00 2001 From: Krzysztof Bieganski Date: Fri, 15 May 2026 02:26:02 +0200 Subject: [PATCH] Optimize force read return values (#7596) --- include/verilated_force.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/include/verilated_force.h b/include/verilated_force.h index 2767200e7..8160fdffb 100644 --- a/include/verilated_force.h +++ b/include/verilated_force.h @@ -222,11 +222,12 @@ public: VlForceVec() = default; template - T read(T val) const { + T read(const T& val) const { + T result = val; if VL_CONSTEXPR_CXX17 (VlForceTypeInfo::unpackedArray) { // Handling the case of a nested flattened array using recursion using ElemRef - = decltype(VlForceArrayIndexer::elem(val, static_cast(0))); + = decltype(VlForceArrayIndexer::elem(result, static_cast(0))); using Elem = VlForceBaseType; const int total = static_cast(VlForceArrayIndexer::size); for (const auto& entry : m_entries) { @@ -236,13 +237,13 @@ public: for (int idx = startIdx; idx <= endIdx; idx++) { const int rhsIndex = idx - entry.m_rhsLsb; const std::size_t uidx = static_cast(idx); - VlForceArrayIndexer::elem(val, uidx) = rhsBasep[rhsIndex]; + VlForceArrayIndexer::elem(result, uidx) = rhsBasep[rhsIndex]; } } - return val; + return result; } - applyEntries(val); - return val; + applyEntries(result); + return result; } template