From b98be0c2e7f2a333e6663eebfa90748d3f7ffe91 Mon Sep 17 00:00:00 2001 From: toxieainc Date: Mon, 11 Jul 2022 18:47:13 +0200 Subject: [PATCH] optimize ReadRegister, as localtime (at least on MSVC/Windows) is significantly showing up in profiling e.g. in SW Trilogy caches localtime until time changes (i.e. limits calls to 1/sec) --- Src/Model3/RTC72421.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Src/Model3/RTC72421.cpp b/Src/Model3/RTC72421.cpp index 7cc2c27..d5490ef 100644 --- a/Src/Model3/RTC72421.cpp +++ b/Src/Model3/RTC72421.cpp @@ -33,7 +33,7 @@ #include "RTC72421.h" -#include +#include #include "Supermodel.h" @@ -43,11 +43,16 @@ UINT8 CRTC72421::ReadRegister(unsigned reg) { - time_t currentTime; - struct tm *Time; + static time_t oldTime{0}; + time_t currentTime; + static struct tm *Time; time(¤tTime); - Time = localtime(¤tTime); + if (currentTime != oldTime) + { + Time = localtime(¤tTime); + oldTime = currentTime; + } switch (reg&0xF) {