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)
This commit is contained in:
toxieainc 2022-07-11 18:47:13 +02:00
parent ba7145df52
commit b98be0c2e7

View file

@ -33,7 +33,7 @@
#include "RTC72421.h"
#include <time.h>
#include <ctime>
#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(&currentTime);
Time = localtime(&currentTime);
if (currentTime != oldTime)
{
Time = localtime(&currentTime);
oldTime = currentTime;
}
switch (reg&0xF)
{