Skip to content

Commit

Permalink
Optimize map accesses in LadspaManager (#7173)
Browse files Browse the repository at this point in the history
Some methods in `LadspaManager` performed repeated searches through the map by first calling `contains` and then by actually fetching the entry. This is fixed by using `find` on the map. It returns an iterator which can directly provide the result or indicate that nothing was found. That way the map is only searched once.
  • Loading branch information
michaelgregorius committed Mar 30, 2024
1 parent 9c591b1 commit a98c700
Showing 1 changed file with 19 additions and 35 deletions.
54 changes: 19 additions & 35 deletions src/core/LadspaManager.cpp
Expand Up @@ -122,14 +122,8 @@ LadspaManager::~LadspaManager()
LadspaManagerDescription * LadspaManager::getDescription(
const ladspa_key_t & _plugin )
{
if( m_ladspaManagerMap.contains( _plugin ) )
{
return( m_ladspaManagerMap[_plugin] );
}
else
{
return( nullptr );
}
auto const it = m_ladspaManagerMap.find(_plugin);
return it != m_ladspaManagerMap.end() ? *it : nullptr;
}


Expand Down Expand Up @@ -519,24 +513,16 @@ bool LadspaManager::isInteger( const ladspa_key_t & _plugin,

bool LadspaManager::isEnum( const ladspa_key_t & _plugin, uint32_t _port )
{
if( m_ladspaManagerMap.contains( _plugin )
&& _port < getPortCount( _plugin ) )
auto const * desc = getDescriptor(_plugin);
if (desc && _port < desc->PortCount)
{
LADSPA_Descriptor_Function descriptorFunction =
m_ladspaManagerMap[_plugin]->descriptorFunction;
const LADSPA_Descriptor * descriptor =
descriptorFunction(
m_ladspaManagerMap[_plugin]->index );
LADSPA_PortRangeHintDescriptor hintDescriptor =
descriptor->PortRangeHints[_port].HintDescriptor;
desc->PortRangeHints[_port].HintDescriptor;
// This is an LMMS extension to ladspa
return( LADSPA_IS_HINT_INTEGER( hintDescriptor ) &&
LADSPA_IS_HINT_TOGGLED( hintDescriptor ) );
}
else
{
return( false );
return LADSPA_IS_HINT_INTEGER(hintDescriptor) && LADSPA_IS_HINT_TOGGLED(hintDescriptor);
}

return false;
}


Expand All @@ -562,22 +548,20 @@ const void * LadspaManager::getImplementationData(



const LADSPA_Descriptor * LadspaManager::getDescriptor(
const ladspa_key_t & _plugin )
const LADSPA_Descriptor * LadspaManager::getDescriptor(const ladspa_key_t & _plugin)
{
if( m_ladspaManagerMap.contains( _plugin ) )
{
LADSPA_Descriptor_Function descriptorFunction =
m_ladspaManagerMap[_plugin]->descriptorFunction;
const LADSPA_Descriptor * descriptor =
descriptorFunction(
m_ladspaManagerMap[_plugin]->index );
return( descriptor );
}
else
auto const it = m_ladspaManagerMap.find(_plugin);
if (it != m_ladspaManagerMap.end())
{
return( nullptr );
auto const plugin = *it;

LADSPA_Descriptor_Function descriptorFunction = plugin->descriptorFunction;
const LADSPA_Descriptor* descriptor = descriptorFunction(plugin->index);

return descriptor;
}

return nullptr;
}


Expand Down

0 comments on commit a98c700

Please sign in to comment.