Skip to content

Commit

Permalink
Nano optimization: swap metadata factory function resolve
Browse files Browse the repository at this point in the history
Because it's just WFS who uses the multipleProviderMetadataFactory

Barely measurable but measurable (~5 ms on my machine)
  • Loading branch information
elpaso authored and nyalldawson committed Nov 27, 2020
1 parent 8f4a3c6 commit bbc6408
Showing 1 changed file with 29 additions and 26 deletions.
55 changes: 29 additions & 26 deletions src/core/qgsproviderregistry.cpp
Expand Up @@ -215,12 +215,13 @@ void QgsProviderRegistry::init()
continue;
}

QFunctionPointer multi_func = myLib.resolve( QStringLiteral( "multipleProviderMetadataFactory" ).toLatin1().data() );
multiple_factory_function *multi_function = reinterpret_cast< multiple_factory_function * >( cast_to_fptr( multi_func ) );
if ( multi_function )
bool libraryLoaded { false };
QFunctionPointer func = myLib.resolve( QStringLiteral( "providerMetadataFactory" ).toLatin1().data() );
factory_function *function = reinterpret_cast< factory_function * >( cast_to_fptr( func ) );
if ( function )
{
std::vector<QgsProviderMetadata *> *metadatas = multi_function();
for ( const auto meta : *metadatas )
QgsProviderMetadata *meta = function();
if ( meta )
{
if ( findMetadata_( mProviders, meta->key() ) )
{
Expand All @@ -230,36 +231,38 @@ void QgsProviderRegistry::init()
}
// add this provider to the provider map
mProviders[meta->key()] = meta;
libraryLoaded = true;
}
delete metadatas;
}
else
{
QFunctionPointer func = myLib.resolve( QStringLiteral( "providerMetadataFactory" ).toLatin1().data() );
factory_function *function = reinterpret_cast< factory_function * >( cast_to_fptr( func ) );
if ( !function )
{
QgsDebugMsgLevel( QStringLiteral( "Checking %1: ...invalid (no providerMetadataFactory method)" ).arg( myLib.fileName() ), 2 );
continue;
}

QgsProviderMetadata *meta = function();
if ( !meta )
QFunctionPointer multi_func = myLib.resolve( QStringLiteral( "multipleProviderMetadataFactory" ).toLatin1().data() );
multiple_factory_function *multi_function = reinterpret_cast< multiple_factory_function * >( cast_to_fptr( multi_func ) );
if ( multi_function )
{
QgsDebugMsg( QStringLiteral( "Checking %1: ...invalid (no metadata returned)" ).arg( myLib.fileName() ) );
continue;
std::vector<QgsProviderMetadata *> *metadatas = multi_function();
for ( const auto meta : *metadatas )
{
if ( findMetadata_( mProviders, meta->key() ) )
{
QgsDebugMsg( QStringLiteral( "Checking %1: ...invalid (key %2 already registered)" ).arg( myLib.fileName() ).arg( meta->key() ) );
delete meta;
continue;
}
// add this provider to the provider map
mProviders[meta->key()] = meta;
libraryLoaded = true;
}
delete metadatas;
}
}

if ( findMetadata_( mProviders, meta->key() ) )
{
QgsDebugMsg( QStringLiteral( "Checking %1: ...invalid (key %2 already registered)" ).arg( myLib.fileName() ).arg( meta->key() ) );
delete meta;
continue;
}
// add this provider to the provider map
mProviders[meta->key()] = meta;
if ( ! libraryLoaded )
{
QgsDebugMsgLevel( QStringLiteral( "Checking %1: ...invalid (no providerMetadataFactory method)" ).arg( myLib.fileName() ), 2 );
}
}

#endif
QgsDebugMsg( QStringLiteral( "Loaded %1 providers (%2) " ).arg( mProviders.size() ).arg( providerList().join( ';' ) ) );

Expand Down

0 comments on commit bbc6408

Please sign in to comment.