HW/HSP: Ensure an IHSPDevice object always exists to remove null checks as a micro optimization.
This commit is contained in:
1 parent
207fe1f5de
commit
187fcfa7dc
2 files changed
+16
-22
No files matched your search
@@ -16,54 +16,49 @@ HSPManager::~HSPManager() = default;
|
|||||||
|
|
||||||
void HSPManager::Init()
|
void HSPManager::Init()
|
||||||
{
|
{
|
||||||
AddDevice(Config::Get(Config::MAIN_HSP_DEVICE));
|
SetDevice(Config::Get(Config::MAIN_HSP_DEVICE));
|
||||||
}
|
}
|
||||||
|
|
||||||
void HSPManager::Shutdown()
|
void HSPManager::Shutdown()
|
||||||
{
|
{
|
||||||
RemoveDevice();
|
m_device.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 HSPManager::Read(u32 address)
|
u64 HSPManager::Read(u32 address)
|
||||||
{
|
{
|
||||||
DEBUG_LOG_FMT(HSP, "HSP read from 0x{:08x}", address);
|
DEBUG_LOG_FMT(HSP, "HSP read from 0x{:08x}", address);
|
||||||
if (m_device)
|
|
||||||
return m_device->Read(address);
|
return m_device->Read(address);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HSPManager::Write(u32 address, u64 value)
|
void HSPManager::Write(u32 address, u64 value)
|
||||||
{
|
{
|
||||||
DEBUG_LOG_FMT(HSP, "HSP write to 0x{:08x}: 0x{:016x}", address, value);
|
DEBUG_LOG_FMT(HSP, "HSP write to 0x{:08x}: 0x{:016x}", address, value);
|
||||||
if (m_device)
|
|
||||||
m_device->Write(address, value);
|
m_device->Write(address, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HSPManager::DoState(PointerWrap& p)
|
void HSPManager::DoState(PointerWrap& p)
|
||||||
{
|
{
|
||||||
HSPDeviceType type = m_device->GetDeviceType();
|
const HSPDeviceType current_type = m_device->GetDeviceType();
|
||||||
p.Do(type);
|
auto state_type = current_type;
|
||||||
|
p.Do(state_type);
|
||||||
|
|
||||||
// If the type doesn't match, switch to the right device type
|
// If the type doesn't match, switch to the right device type
|
||||||
if (type != m_device->GetDeviceType())
|
if (state_type != current_type)
|
||||||
AddDevice(type);
|
SetDevice(state_type);
|
||||||
|
|
||||||
m_device->DoState(p);
|
m_device->DoState(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HSPManager::AddDevice(std::unique_ptr<IHSPDevice> device)
|
void HSPManager::SetDevice(std::unique_ptr<IHSPDevice> device)
|
||||||
{
|
{
|
||||||
// Set the new one
|
|
||||||
m_device = std::move(device);
|
m_device = std::move(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HSPManager::AddDevice(const HSPDeviceType device)
|
void HSPManager::SetDevice(const HSPDeviceType device)
|
||||||
{
|
{
|
||||||
AddDevice(HSPDevice_Create(device));
|
SetDevice(HSPDevice_Create(device));
|
||||||
}
|
}
|
||||||
|
|
||||||
void HSPManager::RemoveDevice()
|
|
||||||
{
|
|
||||||
m_device.reset();
|
|
||||||
}
|
|
||||||
} // namespace HSP
|
} // namespace HSP
|
||||||
@@ -32,9 +32,8 @@ public:
|
|||||||
|
|
||||||
void DoState(PointerWrap& p);
|
void DoState(PointerWrap& p);
|
||||||
|
|
||||||
void RemoveDevice();
|
void SetDevice(std::unique_ptr<IHSPDevice> device);
|
||||||
void AddDevice(std::unique_ptr<IHSPDevice> device);
|
void SetDevice(HSPDeviceType device);
|
||||||
void AddDevice(HSPDeviceType device);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<IHSPDevice> m_device;
|
std::unique_ptr<IHSPDevice> m_device;
|
||||||
|
|||||||
Reference in new issue
Block a user