Speeding-up CSS parsing for big one-line ones

This commit is contained in:
Abs62 2017-10-07 23:33:02 +03:00
parent b777cd8e18
commit 8edb5435d8

View file

@ -275,9 +275,6 @@ bool Class::loadIconFromFile( QString const & _filename, bool isFullName )
void Class::isolateCSS( QString & css, QString const & wrapperSelector ) void Class::isolateCSS( QString & css, QString const & wrapperSelector )
{ {
QRegExp namespaceRegExp( "(\\w+|\\*)\\|" );
namespaceRegExp.setMinimal( true );
if( css.isEmpty() ) if( css.isEmpty() )
return; return;
@ -363,19 +360,24 @@ void Class::isolateCSS( QString & css, QString const & wrapperSelector )
if( ch.isLetter() || ch == '*' ) if( ch.isLetter() || ch == '*' )
{ {
// Check for namespace prefix // Check for namespace prefix
int n = css.indexOf( '\n', currentPos ); QChar chr;
if( n > currentPos || n < 0 ) for( int i = currentPos; i < css.length(); i++ )
{ {
QString str = css.mid( currentPos, n < 0 ? -1 : n - currentPos ); chr = css[ i ];
if( str.indexOf( namespaceRegExp ) == 0 ) if( chr.isLetterOrNumber() || chr.isMark() || chr == '_' || chr == '-'
{ || ( chr == '*' && i == currentPos ) )
// Copy prefix as is
QString space = namespaceRegExp.cap( 0 );
newCSS.append( space );
currentPos += space.length();
continue; continue;
if( chr == '|' )
{
// Namespace prefix found, copy it as is
newCSS.append( css.mid( currentPos, i - currentPos + 1 ) );
currentPos = i + 1;
} }
break;
} }
if ( chr == '|' )
continue;
} }
// This is some selector. // This is some selector.