Commit 0ce016c1 by Jamie Madill Committed by Commit Bot

FixedVector: Add "full" method.

Will be useful for an optimization to the Buffer Subject/Observer pattern. Also cleans up an ASSERT. Bug: angleproject:2389 Bug: chromium:829906 Change-Id: I2f8313ab531bca61947a51cc2396c04fb5d4bb1d Reviewed-on: https://chromium-review.googlesource.com/1002883Reviewed-by: 's avatarLuc Ferron <lucferron@chromium.org> Reviewed-by: 's avatarLingfeng Yang <lfy@google.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent bb52c523
......@@ -80,6 +80,8 @@ class FixedVector final
void resize(size_type count);
void resize(size_type count, const value_type &value);
bool full() const;
private:
void assign_from_initializer_list(std::initializer_list<value_type> init);
......@@ -245,7 +247,7 @@ void FixedVector<T, N, Storage>::clear()
template <class T, size_t N, class Storage>
void FixedVector<T, N, Storage>::push_back(const value_type &value)
{
ASSERT(mSize + 1 <= N);
ASSERT(mSize < N);
mStorage[mSize] = value;
mSize++;
}
......@@ -253,7 +255,7 @@ void FixedVector<T, N, Storage>::push_back(const value_type &value)
template <class T, size_t N, class Storage>
void FixedVector<T, N, Storage>::push_back(value_type &&value)
{
ASSERT(mSize + 1 <= N);
ASSERT(mSize < N);
mStorage[mSize] = std::move(value);
mSize++;
}
......@@ -318,6 +320,12 @@ void FixedVector<T, N, Storage>::assign_from_initializer_list(
mSize++;
}
}
template <class T, size_t N, class Storage>
bool FixedVector<T, N, Storage>::full() const
{
return (mSize == N);
}
} // namespace angle
#endif // COMMON_FIXEDVECTOR_H_
......@@ -134,4 +134,15 @@ TEST(FixedVector, Iteration)
EXPECT_EQ(4, vistedCount);
}
// Test the "full" method.
TEST(FixedVector, Full)
{
FixedVector<int, 2> vec;
EXPECT_FALSE(vec.full());
vec.push_back(0);
EXPECT_FALSE(vec.full());
vec.push_back(1);
EXPECT_TRUE(vec.full());
}
} // namespace angle
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