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 all 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
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
15 changes: 10 additions & 5 deletions avogadro/core/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,18 @@ class ArrayRefContainer
explicit ArrayRefContainer(const size_t n,
const ValueType& value = ValueType())
: m_ref(1), data(n, value)
{}
{
}

ArrayRefContainer(const ArrayRefContainer& other) : m_ref(1), data(other.data)
{}
{
}

template <typename InputIterator>
ArrayRefContainer(InputIterator first, InputIterator last)
: m_ref(1), data(first, last)
{}
{
}

// Increment the reference count.
void reref() { ++m_ref; }
Expand Down Expand Up @@ -118,11 +121,13 @@ class Array

explicit Array(const size_t n, const ValueType& value = ValueType())
: d(new Container(n, value))
{}
{
}

template <typename InputIterator>
Array(InputIterator first, InputIterator last) : d(new Container(first, last))
{}
{
}

/** Copy constructor, note the copy made of the internal data of other. */
Array(const Array& other)
Expand Down
9 changes: 4 additions & 5 deletions avogadro/core/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class AVOGADROCORE_EXPORT Variant

/** Creates a variant to store @p value. */
template <typename T>
Variant(T value);
explicit Variant(T value);

/** Creates a new copy of @p variant. */
inline Variant(const Variant& variant);
Expand Down Expand Up @@ -130,8 +130,7 @@ class AVOGADROCORE_EXPORT Variant
template <typename T>
static T lexical_cast(const std::string& string);

private:
Type m_type;
private : Type m_type;
union
{
bool _bool;
Expand All @@ -146,8 +145,8 @@ class AVOGADROCORE_EXPORT Variant
} m_value;
};

} // end Core namespace
} // end Avogadro namespace
} // namespace Core
} // namespace Avogadro

#include "variant-inline.h"

Expand Down
Loading