From b5213567f4935372229f021445728f510b2ed7c3 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 10 Oct 2015 13:16:59 -0400 Subject: [PATCH] GBI: Move initial microcode search to its own function --- src/GBI.cpp | 22 ++++++++++++++++------ src/GBI.h | 1 + 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/GBI.cpp b/src/GBI.cpp index 1738f3ab..922e5aa2 100644 --- a/src/GBI.cpp +++ b/src/GBI.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -211,14 +212,23 @@ bool _isDigit(char _c) return _c >= '0' && _c <= '9'; } +bool GBIInfo::_makeExistingMicrocodeCurrent(u32 uc_start, u32 uc_dstart, u32 uc_dsize) +{ + auto iter = std::find_if(m_list.begin(), m_list.end(), [=](const MicrocodeInfo& info) { + return info.address == uc_start && info.dataAddress == uc_dstart && info.dataSize == uc_dsize; + }); + + if (iter == m_list.end()) + return false; + + _makeCurrent(&*iter); + return true; +} + void GBIInfo::loadMicrocode(u32 uc_start, u32 uc_dstart, u16 uc_dsize) { - for (Microcodes::iterator iter = m_list.begin(); iter != m_list.end(); ++iter) { - if (iter->address == uc_start && iter->dataAddress == uc_dstart && iter->dataSize == uc_dsize) { - _makeCurrent(&(*iter)); - return; - } - } + if (_makeExistingMicrocodeCurrent(uc_start, uc_dstart, uc_dsize)) + return; m_list.emplace_front(); MicrocodeInfo & current = m_list.front(); diff --git a/src/GBI.h b/src/GBI.h index f4791285..c4c57a2d 100644 --- a/src/GBI.h +++ b/src/GBI.h @@ -699,6 +699,7 @@ struct GBIInfo private: void _makeCurrent(MicrocodeInfo * _pCurrent); + bool _makeExistingMicrocodeCurrent(u32 uc_start, u32 uc_dstart, u32 uc_dsize); MicrocodeInfo * m_pCurrent;