Avoid some other lengthy lambdas in call_once

This commit is contained in:
Nyall Dawson 2025-05-29 10:53:23 +10:00
parent 7906258d01
commit 8159590ecf
6 changed files with 136 additions and 147 deletions

View File

@ -194,10 +194,7 @@ void QgsCallout::setEnabled( bool enabled )
QgsPropertiesDefinition QgsCallout::propertyDefinitions()
{
static std::once_flag initialized;
std::call_once( initialized, [ = ]( )
{
initPropertyDefinitions();
} );
std::call_once( initialized, initPropertyDefinitions );
return sPropertyDefinitions;
}

View File

@ -123,11 +123,7 @@ void QgsNetworkDiskCache::clear()
return sDiskCache.clear();
}
qint64 QgsNetworkDiskCache::smartCacheSize( const QString &cacheDir )
{
static qint64 cacheSize = 0;
static std::once_flag initialized;
std::call_once( initialized, [ = ]
void determineSmartCacheSize( const QString &cacheDir, qint64 &cacheSize )
{
std::function<qint64( const QString & )> dirSize;
dirSize = [&dirSize]( const QString & dirPath ) -> qint64
@ -184,14 +180,19 @@ qint64 QgsNetworkDiskCache::smartCacheSize( const QString &cacheDir )
// Add 16% of free space up to 500 MB
cacheSize10MB += std::max( 2LL, static_cast<qint64>( available10MB * 0.16 ) );
#else
#else \
// Add 30% of free space up to 500 MB
cacheSize10MB += std::max( 5LL, static_cast<qint64>( available10MB * 0.30 ) );
#endif
}
cacheSize = cacheSize10MB * 10 * 1024 * 1024;
// NOLINTEND(bugprone-narrowing-conversions)
} );
return cacheSize;
}
qint64 QgsNetworkDiskCache::smartCacheSize( const QString &cacheDir )
{
static qint64 sCacheSize = 0;
static std::once_flag initialized;
std::call_once( initialized, determineSmartCacheSize, cacheDir, sCacheSize );
return sCacheSize;
}

View File

@ -2961,7 +2961,7 @@ void buildSupportedRasterFileFilterAndExtensions( QString &fileFiltersString, QS
QgsDebugMsgLevel( "Raster filter list built: " + fileFiltersString, 2 );
QgsDebugMsgLevel( "Raster extension list built: " + extensions.join( ' ' ), 2 );
} // buildSupportedRasterFileFilter_()
}
bool QgsGdalProvider::isValidRasterFileName( QString const &fileNameQString, QString &retErrMsg )
{
@ -4429,12 +4429,7 @@ QList<QgsProviderSublayerDetails> QgsGdalProviderMetadata::querySublayers( const
// get supported extensions
static std::once_flag initialized;
std::call_once( initialized, [ = ]
{
buildSupportedRasterFileFilterAndExtensions( sFilterString, sExtensions, sWildcards );
QgsDebugMsgLevel( QStringLiteral( "extensions: " ) + sExtensions.join( ' ' ), 2 );
QgsDebugMsgLevel( QStringLiteral( "wildcards: " ) + sWildcards.join( ' ' ), 2 );
} );
std::call_once( initialized, buildSupportedRasterFileFilterAndExtensions, sFilterString, sExtensions, sWildcards );
const QString suffix = uriParts.value( QStringLiteral( "vsiSuffix" ) ).toString().isEmpty()
? pathInfo.suffix().toLower()

View File

@ -226,38 +226,7 @@ QgsApplication::QgsApplication( int &argc, char **argv, bool GUIenabled, const Q
}
void QgsApplication::init( QString profileFolder )
{
// Initialize application members in desktop app (at this point, profile folder is known)
if ( platform() == QLatin1String( "desktop" ) )
{
instance()->mApplicationMembers = new ApplicationMembers();
instance()->mApplicationMembers->mSettingsRegistryCore->migrateOldSettings();
}
if ( profileFolder.isEmpty() )
{
if ( getenv( "QGIS_CUSTOM_CONFIG_PATH" ) )
{
profileFolder = getenv( "QGIS_CUSTOM_CONFIG_PATH" );
}
else
{
profileFolder = QStandardPaths::standardLocations( QStandardPaths::AppDataLocation ).value( 0 );
}
// This will normally get here for custom scripts that use QgsApplication.
// This doesn't get this hit for QGIS Desktop because we setup the profile via main
QString rootProfileFolder = QgsUserProfileManager::resolveProfilesFolder( profileFolder );
QgsUserProfileManager manager( rootProfileFolder );
QgsUserProfile *profile = manager.getProfile();
profileFolder = profile->folder();
delete profile;
}
*sProfilePath() = profileFolder;
static std::once_flag sMetaTypesRegistered;
std::call_once( sMetaTypesRegistered, []
void registerMetaTypes()
{
qRegisterMetaType<QgsGeometry::Error>( "QgsGeometry::Error" );
qRegisterMetaType<QgsDatabaseQueryLogEntry>( "QgsDatabaseQueryLogEntry" );
@ -322,7 +291,40 @@ void QgsApplication::init( QString profileFolder )
qRegisterMetaType< QAuthenticator * >( "QAuthenticator*" );
qRegisterMetaType< QgsGpsInformation >( "QgsGpsInformation" );
qRegisterMetaType< QgsSensorThingsExpansionDefinition >( "QgsSensorThingsExpansionDefinition" );
} );
};
void QgsApplication::init( QString profileFolder )
{
// Initialize application members in desktop app (at this point, profile folder is known)
if ( platform() == QLatin1String( "desktop" ) )
{
instance()->mApplicationMembers = new ApplicationMembers();
instance()->mApplicationMembers->mSettingsRegistryCore->migrateOldSettings();
}
if ( profileFolder.isEmpty() )
{
if ( getenv( "QGIS_CUSTOM_CONFIG_PATH" ) )
{
profileFolder = getenv( "QGIS_CUSTOM_CONFIG_PATH" );
}
else
{
profileFolder = QStandardPaths::standardLocations( QStandardPaths::AppDataLocation ).value( 0 );
}
// This will normally get here for custom scripts that use QgsApplication.
// This doesn't get this hit for QGIS Desktop because we setup the profile via main
QString rootProfileFolder = QgsUserProfileManager::resolveProfilesFolder( profileFolder );
QgsUserProfileManager manager( rootProfileFolder );
QgsUserProfile *profile = manager.getProfile();
profileFolder = profile->folder();
delete profile;
}
*sProfilePath() = profileFolder;
static std::once_flag sMetaTypesRegistered;
std::call_once( sMetaTypesRegistered, registerMetaTypes );
( void ) resolvePkgPath();

View File

@ -124,10 +124,7 @@ void QgsMapLayerElevationProperties::setDataDefinedProperties( const QgsProperty
QgsPropertiesDefinition QgsMapLayerElevationProperties::propertyDefinitions()
{
static std::once_flag initialized;
std::call_once( initialized, [ = ]( )
{
initPropertyDefinitions();
} );
std::call_once( initialized, initPropertyDefinitions );
return sPropertyDefinitions;
}

View File

@ -454,9 +454,6 @@ void QgsRasterPipe::initPropertyDefinitions()
QgsPropertiesDefinition QgsRasterPipe::propertyDefinitions()
{
static std::once_flag initialized;
std::call_once( initialized, [ = ]( )
{
initPropertyDefinitions();
} );
std::call_once( initialized, initPropertyDefinitions );
return sPropertyDefinitions;
}