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
Changes from 1 commit
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
22 changes: 12 additions & 10 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,19 +121,18 @@ 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)
{
other.d->reref();
d = other.d;
}

/** Copy constructor, note the copy made of the internal data of other. */
Array(const Array& other) : d(new Container(*other.d)) {}
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, we don't want to do this. The Array class is copy-on-write. Please remove and/or tell cppcheck to ignore this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

//'d' is allocated new memory and a deep copy is one

~Array();

/**
Expand Down
Loading