Commit 9b61930c authored by alancutter's avatar alancutter Committed by Commit bot

Remove redundant size member from InterpolableList

The size of the list can be read from the m_values vector, no need to
store the size separately.

Review-Url: https://codereview.chromium.org/2273233002
Cr-Commit-Position: refs/heads/master@{#414330}
parent c6f28a1e
......@@ -16,9 +16,9 @@ bool InterpolableNumber::equals(const InterpolableValue& other) const
bool InterpolableList::equals(const InterpolableValue& other) const
{
const InterpolableList& otherList = toInterpolableList(other);
if (m_size != otherList.m_size)
if (length() != otherList.length())
return false;
for (size_t i = 0; i < m_size; i++) {
for (size_t i = 0; i < length(); i++) {
if (!m_values[i]->equals(*otherList.m_values[i]))
return false;
}
......@@ -54,10 +54,10 @@ void InterpolableList::interpolate(const InterpolableValue& to, const double pro
const InterpolableList& toList = toInterpolableList(to);
InterpolableList& resultList = toInterpolableList(result);
DCHECK_EQ(toList.m_size, m_size);
DCHECK_EQ(resultList.m_size, m_size);
DCHECK_EQ(toList.length(), length());
DCHECK_EQ(resultList.length(), length());
for (size_t i = 0; i < m_size; i++) {
for (size_t i = 0; i < length(); i++) {
DCHECK(m_values[i]);
DCHECK(toList.m_values[i]);
m_values[i]->interpolate(*(toList.m_values[i]), progress, *(resultList.m_values[i]));
......@@ -66,8 +66,8 @@ void InterpolableList::interpolate(const InterpolableValue& to, const double pro
std::unique_ptr<InterpolableValue> InterpolableList::cloneAndZero() const
{
std::unique_ptr<InterpolableList> result = InterpolableList::create(m_size);
for (size_t i = 0; i < m_size; i++)
std::unique_ptr<InterpolableList> result = InterpolableList::create(length());
for (size_t i = 0; i < length(); i++)
result->set(i, m_values[i]->cloneAndZero());
return std::move(result);
}
......@@ -79,7 +79,7 @@ void InterpolableNumber::scale(double scale)
void InterpolableList::scale(double scale)
{
for (size_t i = 0; i < m_size; i++)
for (size_t i = 0; i < length(); i++)
m_values[i]->scale(scale);
}
......@@ -91,8 +91,8 @@ void InterpolableNumber::scaleAndAdd(double scale, const InterpolableValue& othe
void InterpolableList::scaleAndAdd(double scale, const InterpolableValue& other)
{
const InterpolableList& otherList = toInterpolableList(other);
DCHECK_EQ(otherList.m_size, m_size);
for (size_t i = 0; i < m_size; i++)
DCHECK_EQ(otherList.length(), length());
for (size_t i = 0; i < length(); i++)
m_values[i]->scaleAndAdd(scale, *otherList.m_values[i]);
}
......
......@@ -122,20 +122,17 @@ public:
bool isList() const final { return true; }
void set(size_t position, std::unique_ptr<InterpolableValue> value)
{
DCHECK_LT(position, m_size);
m_values[position] = std::move(value);
}
const InterpolableValue* get(size_t position) const
{
DCHECK_LT(position, m_size);
return m_values[position].get();
}
std::unique_ptr<InterpolableValue>& getMutable(size_t position)
{
DCHECK_LT(position, m_size);
return m_values[position];
}
size_t length() const { return m_size; }
size_t length() const { return m_values.size(); }
bool equals(const InterpolableValue& other) const final;
std::unique_ptr<InterpolableValue> clone() const final { return create(*this); }
std::unique_ptr<InterpolableValue> cloneAndZero() const final;
......@@ -145,20 +142,17 @@ public:
private:
void interpolate(const InterpolableValue& to, const double progress, InterpolableValue& result) const final;
explicit InterpolableList(size_t size)
: m_size(size)
, m_values(m_size)
: m_values(size)
{
}
InterpolableList(const InterpolableList& other)
: m_size(other.m_size)
, m_values(m_size)
: m_values(other.length())
{
for (size_t i = 0; i < m_size; i++)
for (size_t i = 0; i < length(); i++)
set(i, other.m_values[i]->clone());
}
size_t m_size;
Vector<std::unique_ptr<InterpolableValue>> m_values;
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment