[postgres] Speed up array parsing (fixes #33226) (#33227)

This commit is contained in:
Hugo Mercier 2019-12-09 10:44:33 +01:00 committed by GitHub
parent 099c62d744
commit ac958dec89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4412,11 +4412,10 @@ static void jumpSpace( const QString &txt, int &i )
QString QgsPostgresProvider::getNextString( const QString &txt, int &i, const QString &sep )
{
jumpSpace( txt, i );
QString cur = txt.mid( i );
if ( cur.startsWith( '"' ) )
if ( i < txt.length() && txt.at( i ) == '"' )
{
QRegExp stringRe( "^\"((?:\\\\.|[^\"\\\\])*)\".*" );
if ( !stringRe.exactMatch( cur ) )
if ( !stringRe.exactMatch( txt.mid( i ) ) )
{
QgsMessageLog::logMessage( tr( "Cannot find end of double quoted string: %1" ).arg( txt ), tr( "PostGIS" ) );
return QString();
@ -4433,14 +4432,17 @@ QString QgsPostgresProvider::getNextString( const QString &txt, int &i, const QS
}
else
{
int sepPos = cur.indexOf( sep );
if ( sepPos < 0 )
int start = i;
for ( ; i < txt.length(); i++ )
{
i += cur.length();
return cur.trimmed();
if ( txt.midRef( i ).startsWith( sep ) )
{
QStringRef r( txt.midRef( start, i - start ) );
i += sep.length();
return r.trimmed().toString();
}
}
i += sepPos + sep.length();
return cur.left( sepPos ).trimmed();
return txt.midRef( start, i - start ).trimmed().toString();
}
}