Skip to content
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

Improving code efficiency by errors from cppcheck #1369

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions avogadro/core/angleiterator.cpp
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also used clang-format on the 2 files.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ using namespace std;

AngleIterator::AngleIterator(const Molecule* mol)
: m_current(0, 0, 0), m_mol(mol)
{}
{
}

Angle AngleIterator::begin()
{
Expand Down Expand Up @@ -44,15 +45,14 @@ Angle AngleIterator::operator++()
if (valid) {
// we have a valid current angle, try to find a new edge
for (const auto maybeC : graph.neighbors(b)) {
if (maybeC != a
&& (!valid || maybeC > c)) {
if (maybeC != a && maybeC > c) {
m_current = make_tuple(a, b, maybeC);
return m_current;
}

} // end "c" loop
} // end "c" loop
valid = false; // we couldn't find a "c", so find a new "a"
} // end if()
} // end if()

// can we find a new edge?
for (const auto maybeA : graph.neighbors(b)) {
Expand All @@ -67,13 +67,13 @@ Angle AngleIterator::operator++()
// if we don't have a valid "a", move out to find a new "b"
} while (valid);

while(!valid && b + 1 < count) {
while (!valid && b + 1 < count) {
++b; // try going to the next atom

const auto neighbors = graph.neighbors(b);
if (neighbors.size() < 2)
continue;

a = neighbors[0];
c = neighbors[0]; // we'll move to the next one in the loop
valid = true;
Expand All @@ -84,4 +84,4 @@ Angle AngleIterator::operator++()
return make_tuple(MaxIndex, MaxIndex, MaxIndex);
} // end ++ operator

} // namespace Avogadro
} // namespace Avogadro::Core
17 changes: 7 additions & 10 deletions avogadro/core/angleiterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

#include "avogadrocore.h"

#include <vector>
#include <tuple>
#include <vector>

namespace Avogadro {
namespace Core {
Expand All @@ -26,28 +26,25 @@ class AVOGADROCORE_EXPORT AngleIterator
/**
* Constructor.
*/
AngleIterator(const Molecule *mol);
explicit AngleIterator(const Molecule* mol);

~AngleIterator() {}

Angle* operator*() {
return &m_current;
}
Angle* operator*() { return &m_current; }

Angle begin();

Angle end() const {
return std::make_tuple(MaxIndex, MaxIndex, MaxIndex);
}
Angle end() const { return std::make_tuple(MaxIndex, MaxIndex, MaxIndex); }

Angle operator++();

bool operator!=(const AngleIterator& other ) {
bool operator!=(const AngleIterator& other)
{
return m_current != other.m_current;
}

private:
Angle m_current;
Angle m_current;
const Molecule* m_mol;
};

Expand Down
Loading