-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cppcheck: fix useStlAlgorithm #59
Conversation
src/libcmis/gdrive-document.cxx:76:13: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm] src/libcmis/gdrive-document.cxx:89:0: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm] src/libcmis/gdrive-document.cxx:95:0: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm] src/libcmis/json-utils.cxx:164:14: style: Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]
src/libcmis/gdrive-document.cxx
Outdated
@@ -69,35 +70,48 @@ string GDriveDocument::getDownloadUrl( string streamId ) | |||
if ( !streamId.empty( ) ) | |||
{ | |||
// Find the rendition associated with the streamId | |||
for ( vector< RenditionPtr >::iterator it = renditions.begin( ) ; | |||
it != renditions.end(); ++it ) | |||
std::vector<RenditionPtr>::iterator it = std::find_if(renditions.begin(), renditions.end(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH, I don't think this improves the code in any way... If you really want to touch this, maybe using foreach loops would be better? That should make the code easier to read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to be sure, before I do anything wrong, do you prefer a foreach for the 4 changes or only for this one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For all of them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok done.
src/libcmis/gdrive-document.cxx:76:13: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm] src/libcmis/gdrive-document.cxx:89:0: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm] src/libcmis/gdrive-document.cxx:95:0: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm] src/libcmis/json-utils.cxx:164:14: style: Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]
… into useStlAlgorithm
… into useStlAlgorithm
… into useStlAlgorithm
src/libcmis/gdrive-document.cxx
Outdated
if ( (*it)->getMimeType( ).find( "opendocument") != string::npos ) | ||
return (*it)->getUrl( ); | ||
for (const auto& renditionPtr : renditions) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't add extra braces unless needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok done
src/libcmis/gdrive-document.cxx
Outdated
@@ -69,35 +69,39 @@ string GDriveDocument::getDownloadUrl( string streamId ) | |||
if ( !streamId.empty( ) ) | |||
{ | |||
// Find the rendition associated with the streamId | |||
for ( vector< RenditionPtr >::iterator it = renditions.begin( ) ; | |||
it != renditions.end(); ++it ) | |||
for (const auto& renditionPtr : renditions) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please try to follow the coding style of the surrounding code. (I don't like it very much myself, but, on my list, consistency is higher than personal preference.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure to understand here, do you mean I should use:
for (const auto& renditionPtr
: renditions)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, that doesn't make much sense. What I mean is: try to use the same indentation, spaces around stuff, etc. like the surrounding code. E.g.,
if ( renditionPtr->getStreamId( ) == streamId )
instead of
if (renditionPtr->getStreamId() == streamId)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I added spaces on all locations I had changed.
Hope it's ok now.
src/libcmis/gdrive-document.cxx
Outdated
@@ -27,6 +27,7 @@ | |||
*/ | |||
|
|||
#include "gdrive-document.hxx" | |||
#include <algorithm> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, please use git commit --amend
or git rebase --interactive
to make "perfect" commits (followed by git push --force
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried too but sometimes the push is rejected on my local branch.
This time it seemed ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good code-wise, just some style issues.
… into useStlAlgorithm
… into useStlAlgorithm
Is there anything I should change or is it ok? |
… into useStlAlgorithm
… into useStlAlgorithm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
src/libcmis/gdrive-document.cxx:76:13: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]
src/libcmis/gdrive-document.cxx:89:0: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]
src/libcmis/gdrive-document.cxx:95:0: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]
src/libcmis/json-utils.cxx:164:14: style: Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm]