D24212: Remove foreach in KmPlot in favor of range-based loops

Albert Astals Cid noreply at phabricator.kde.org
Thu Sep 26 22:41:32 BST 2019


aacid added a comment.


  There's some more other lists that maybe are not const, not sure if we care a lot though, but it's always too have "the best code possible"
  
  Up to you if you want to change it or not

INLINE COMMENTS

> equationhighlighter.cpp:72
>  	
>  	QStringList variables = m_parent->m_equation->variables();
>  	QStringList functions = XParser::self()->predefinedFunctions(true) + XParser::self()->userFunctions();

mark variables and functions as const?

> function.cpp:392
>  			listSplit = m_fstr.mid( p1+1, p2-p1-1 ).split( ',', QString::SkipEmptyParts );
>  		
>  		// Variables shouldn't contain spaces!

what would you think of

const QStringList listSplit = ( (p1 != -1) && (p2 != -1)  ) ? m_fstr.mid( p1+1, p2-p1-1 ).split( ',', QString::SkipEmptyParts ) : {};

> function.cpp:622
>  {
> -	foreach ( Equation * e, eq )
> +	for ( Equation * e : eq )
>  		delete e;

qDeleteAll?

> function.cpp:834
>  		{
> -			foreach ( Plot plot, list ) { //krazy:exclude=foreach
> +			for ( Plot plot : list ) {
>  				if ( !plotAppearance(p).visible )

qAsConst?

> function.cpp:851
>  		{
> -			foreach ( Plot plot, list ) { //krazy:exclude=foreach
> +			for ( Plot plot : list ) {
>  				plot.stateNumber = i;

qAsConst?

> function.cpp:881
>  		QList< Plot > duplicated;
> -		foreach ( const QVector<bool> &signature, signatures )
> +		for ( const QVector<bool> &signature : signatures )
>  		{

qAsConst?

> function.cpp:897
>  		
> -			foreach ( Plot plot, list ) { //krazy:exclude=foreach
> +			for ( Plot plot : list ) {
>  				plot.pmSignature = pmSignature;

qAsConst?

> functioneditor.cpp:126
>  		QList<name *> widgets = m_editor->findChildren<name *>(); \
> -		foreach ( name * w, widgets ) \
> +		for ( name * w : widgets ) \
>  			connect( w, SIGNAL(signal), this, SLOT(save()) ); \

qAsConst?

> functioneditor.cpp:233
>  	// Now, any IDs left in currentIDs are of functions that have been deleted
> -	foreach ( FunctionListItem * item, currentFunctionItems )
> +	for ( FunctionListItem * item : currentFunctionItems )
>  	{

qAsConst?

> functioneditor.cpp:729
>  	
> -	foreach ( Equation * eq, f->eq )
> +	for ( Equation * eq : f->eq )
>  		eq->differentialStates.resetToInitial();

qAsConst?

REPOSITORY
  R334 KmPlot

REVISION DETAIL
  https://phabricator.kde.org/D24212

To: yurchor, #kde_edu
Cc: aacid, kde-edu, narvaez, apol
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-edu/attachments/20190926/5643d69f/attachment-0001.html>


More information about the kde-edu mailing list