Skip to content
Permalink
Browse files
Micro optimization
  • Loading branch information
nirvn committed Jul 13, 2021
1 parent 0b12d48 commit 0395ea0c25f9568c549f3be539b7b5e1cde8a487
@@ -113,7 +113,8 @@ bool QgsAuthBasicMethod::updateDataSourceUriItems( QStringList &connectionItems,
}

QString sslMode = QStringLiteral( "prefer" );
int sslModeIdx = connectionItems.indexOf( QRegularExpression( "^sslmode=.*" ) );
const thread_local QRegularExpression sslModeRegExp( "^sslmode=.*" );
int sslModeIdx = connectionItems.indexOf( sslModeRegExp );
if ( sslModeIdx != -1 )
{
sslMode = connectionItems.at( sslModeIdx ).split( '=' ).at( 1 );
@@ -241,7 +242,8 @@ bool QgsAuthBasicMethod::updateDataSourceUriItems( QStringList &connectionItems,
else // Not-ogr
{
QString userparam = "user='" + escapeUserPass( username ) + '\'';
int userindx = connectionItems.indexOf( QRegularExpression( "^user='.*" ) );
const thread_local QRegularExpression userRegExp( "^user='.*" );
int userindx = connectionItems.indexOf( userRegExp );
if ( userindx != -1 )
{
connectionItems.replace( userindx, userparam );
@@ -252,7 +254,8 @@ bool QgsAuthBasicMethod::updateDataSourceUriItems( QStringList &connectionItems,
}

QString passparam = "password='" + escapeUserPass( password ) + '\'';
int passindx = connectionItems.indexOf( QRegularExpression( "^password='.*" ) );
const thread_local QRegularExpression passRegExp( "^password='.*" );
int passindx = connectionItems.indexOf( passRegExp );
if ( passindx != -1 )
{
connectionItems.replace( passindx, passparam );
@@ -264,7 +267,8 @@ bool QgsAuthBasicMethod::updateDataSourceUriItems( QStringList &connectionItems,
// add extra CAs
if ( ! caparam.isEmpty() )
{
int sslcaindx = connectionItems.indexOf( QRegularExpression( "^sslrootcert='.*" ) );
const thread_local QRegularExpression sslcaRegExp( "^sslrootcert='.*" );
int sslcaindx = connectionItems.indexOf( sslcaRegExp );
if ( sslcaindx != -1 )
{
connectionItems.replace( sslcaindx, caparam );
@@ -162,7 +162,8 @@ bool QgsAuthIdentCertMethod::updateDataSourceUriItems( QStringList &connectionIt

// add uri parameters
QString userparam = "user='" + commonName + "'";
int userindx = connectionItems.indexOf( QRegularExpression( "^user='.*" ) );
const thread_local QRegularExpression userRegExp( "^user='.*" );
int userindx = connectionItems.indexOf( userRegExp );
if ( userindx != -1 )
{
connectionItems.replace( userindx, userparam );
@@ -173,7 +174,8 @@ bool QgsAuthIdentCertMethod::updateDataSourceUriItems( QStringList &connectionIt
}

QString certparam = "sslcert='" + certFilePath + "'";
int sslcertindx = connectionItems.indexOf( QRegularExpression( "^sslcert='.*" ) );
const thread_local QRegularExpression sslcertRegExp( "^sslcert='.*" );
int sslcertindx = connectionItems.indexOf( sslcertRegExp );
if ( sslcertindx != -1 )
{
connectionItems.replace( sslcertindx, certparam );
@@ -184,7 +186,8 @@ bool QgsAuthIdentCertMethod::updateDataSourceUriItems( QStringList &connectionIt
}

QString keyparam = "sslkey='" + keyFilePath + "'";
int sslkeyindx = connectionItems.indexOf( QRegularExpression( "^sslkey='.*" ) );
const thread_local QRegularExpression sslkeyRegExp( "^sslkey='.*" );
int sslkeyindx = connectionItems.indexOf( sslkeyRegExp );
if ( sslkeyindx != -1 )
{
connectionItems.replace( sslkeyindx, keyparam );
@@ -195,7 +198,8 @@ bool QgsAuthIdentCertMethod::updateDataSourceUriItems( QStringList &connectionIt
}

QString caparam = "sslrootcert='" + caFilePath + "'";
int sslcaindx = connectionItems.indexOf( QRegularExpression( "^sslrootcert='.*" ) );
const thread_local QRegularExpression sslcaRegExp( "^sslrootcert='.*" );
int sslcaindx = connectionItems.indexOf( sslcaRegExp );
if ( sslcaindx != -1 )
{
connectionItems.replace( sslcaindx, caparam );
@@ -194,7 +194,8 @@ bool QgsAuthPkiPathsMethod::updateDataSourceUriItems( QStringList &connectionIte

// add uri parameters
QString userparam = "user='" + commonName + "'";
int userindx = connectionItems.indexOf( QRegularExpression( "^user='.*" ) );
const thread_local QRegularExpression userRegExp( "^user='.*" );
int userindx = connectionItems.indexOf( userRegExp );
if ( userindx != -1 )
{
connectionItems.replace( userindx, userparam );
@@ -206,7 +207,8 @@ bool QgsAuthPkiPathsMethod::updateDataSourceUriItems( QStringList &connectionIte

// add uri parameters
QString certparam = "sslcert='" + certFilePath + "'";
int sslcertindx = connectionItems.indexOf( QRegularExpression( "^sslcert='.*" ) );
const thread_local QRegularExpression sslcertRegExp( "^sslcert='.*" );
int sslcertindx = connectionItems.indexOf( sslcertRegExp );
if ( sslcertindx != -1 )
{
connectionItems.replace( sslcertindx, certparam );
@@ -217,7 +219,8 @@ bool QgsAuthPkiPathsMethod::updateDataSourceUriItems( QStringList &connectionIte
}

QString keyparam = "sslkey='" + keyFilePath + "'";
int sslkeyindx = connectionItems.indexOf( QRegularExpression( "^sslkey='.*" ) );
const thread_local QRegularExpression sslkeyRegExp( "^sslkey='.*" );
int sslkeyindx = connectionItems.indexOf( sslkeyRegExp );
if ( sslkeyindx != -1 )
{
connectionItems.replace( sslkeyindx, keyparam );
@@ -228,7 +231,8 @@ bool QgsAuthPkiPathsMethod::updateDataSourceUriItems( QStringList &connectionIte
}

QString caparam = "sslrootcert='" + caFilePath + "'";
int sslcaindx = connectionItems.indexOf( QRegularExpression( "^sslrootcert='.*" ) );
const thread_local QRegularExpression sslcaRegExp( "^sslrootcert='.*" );
int sslcaindx = connectionItems.indexOf( sslcaRegExp );
if ( sslcaindx != -1 )
{
connectionItems.replace( sslcaindx, caparam );
@@ -193,7 +193,8 @@ bool QgsAuthPkcs12Method::updateDataSourceUriItems( QStringList &connectionItems

// add uri parameters
QString userparam = "user='" + commonName + "'";
int userindx = connectionItems.indexOf( QRegularExpression( "^user='.*" ) );
const thread_local QRegularExpression userRegExp( "^user='.*" );
int userindx = connectionItems.indexOf( userRegExp );
if ( userindx != -1 )
{
connectionItems.replace( userindx, userparam );
@@ -204,7 +205,8 @@ bool QgsAuthPkcs12Method::updateDataSourceUriItems( QStringList &connectionItems
}

QString certparam = "sslcert='" + certFilePath + "'";
int sslcertindx = connectionItems.indexOf( QRegularExpression( "^sslcert='.*" ) );
const thread_local QRegularExpression sslcertRegExp( "^sslcert='.*" );
int sslcertindx = connectionItems.indexOf( sslcertRegExp );
if ( sslcertindx != -1 )
{
connectionItems.replace( sslcertindx, certparam );
@@ -215,7 +217,8 @@ bool QgsAuthPkcs12Method::updateDataSourceUriItems( QStringList &connectionItems
}

QString keyparam = "sslkey='" + keyFilePath + "'";
int sslkeyindx = connectionItems.indexOf( QRegularExpression( "^sslkey='.*" ) );
const thread_local QRegularExpression sslkeyRegExp( "^sslkey='.*" );
int sslkeyindx = connectionItems.indexOf( sslkeyRegExp );
if ( sslkeyindx != -1 )
{
connectionItems.replace( sslkeyindx, keyparam );
@@ -226,7 +229,8 @@ bool QgsAuthPkcs12Method::updateDataSourceUriItems( QStringList &connectionItems
}

QString caparam = "sslrootcert='" + caFilePath + "'";
int sslcaindx = connectionItems.indexOf( QRegularExpression( "^sslrootcert='.*" ) );
const thread_local QRegularExpression sslcaRegExp( "^sslrootcert='.*" );
int sslcaindx = connectionItems.indexOf( sslcaRegExp );
if ( sslcaindx != -1 )
{
connectionItems.replace( sslcaindx, caparam );
@@ -918,7 +918,8 @@ bool QgsAuthManager::configIdUnique( const QString &id ) const

bool QgsAuthManager::hasConfigId( const QString &txt ) const
{
return txt.indexOf( QRegularExpression( AUTH_CFG_REGEX ) ) != -1;
const thread_local QRegularExpression authCfgRegExp( AUTH_CFG_REGEX );
return txt.indexOf( authCfgRegExp ) != -1;
}

QgsAuthMethodConfigsMap QgsAuthManager::availableAuthMethodConfigs( const QString &dataprovider )
@@ -2437,9 +2438,8 @@ bool QgsAuthManager::updateIgnoredSslErrorsCacheFromConfig( const QgsAuthConfigS
bool QgsAuthManager::updateIgnoredSslErrorsCache( const QString &shahostport, const QList<QSslError> &errors )
{
QMutexLocker locker( mMutex.get() );
const QRegularExpression rx( QRegularExpression::anchoredPattern( "\\S+:\\S+:\\d+" ) );
const QRegularExpressionMatch match = rx.match( shahostport );
if ( !match.hasMatch() )
const thread_local QRegularExpression rx( QRegularExpression::anchoredPattern( "\\S+:\\S+:\\d+" ) );
if ( !rx.match( shahostport ).hasMatch() )
{
QgsDebugMsg( "Passed shahostport does not match \\S+:\\S+:\\d+, "
"e.g. 74a4ef5ea94512a43769b744cda0ca5049a72491:www.example.com:443" );
@@ -119,5 +119,6 @@ void QgsAuthConfigIdEdit::leAuthCfg_textChanged( const QString &txt )

bool QgsAuthConfigIdEdit::isAlphaNumeric( const QString &authcfg )
{
return authcfg.indexOf( QRegularExpression( "([a-z]|[A-Z]|[0-9]){7}" ) ) != -1;
const thread_local QRegularExpression alphaNumericRegExp( "([a-z]|[A-Z]|[0-9]){7}" );
return authcfg.indexOf( alphaNumericRegExp ) != -1;
}

0 comments on commit 0395ea0

Please sign in to comment.