Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 0ce016c

Browse files
null77Commit Bot
authored andcommitted
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/1002883 Reviewed-by: Luc Ferron <[email protected]> Reviewed-by: Lingfeng Yang <[email protected]> Reviewed-by: Jamie Madill <[email protected]> Commit-Queue: Jamie Madill <[email protected]>
1 parent bb52c52 commit 0ce016c

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/common/FixedVector.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ class FixedVector final
8080
void resize(size_type count);
8181
void resize(size_type count, const value_type &value);
8282

83+
bool full() const;
84+
8385
private:
8486
void assign_from_initializer_list(std::initializer_list<value_type> init);
8587

@@ -245,15 +247,15 @@ void FixedVector<T, N, Storage>::clear()
245247
template <class T, size_t N, class Storage>
246248
void FixedVector<T, N, Storage>::push_back(const value_type &value)
247249
{
248-
ASSERT(mSize + 1 <= N);
250+
ASSERT(mSize < N);
249251
mStorage[mSize] = value;
250252
mSize++;
251253
}
252254

253255
template <class T, size_t N, class Storage>
254256
void FixedVector<T, N, Storage>::push_back(value_type &&value)
255257
{
256-
ASSERT(mSize + 1 <= N);
258+
ASSERT(mSize < N);
257259
mStorage[mSize] = std::move(value);
258260
mSize++;
259261
}
@@ -318,6 +320,12 @@ void FixedVector<T, N, Storage>::assign_from_initializer_list(
318320
mSize++;
319321
}
320322
}
323+
324+
template <class T, size_t N, class Storage>
325+
bool FixedVector<T, N, Storage>::full() const
326+
{
327+
return (mSize == N);
328+
}
321329
} // namespace angle
322330

323331
#endif // COMMON_FIXEDVECTOR_H_

src/common/FixedVector_unittest.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,15 @@ TEST(FixedVector, Iteration)
134134
EXPECT_EQ(4, vistedCount);
135135
}
136136

137+
// Test the "full" method.
138+
TEST(FixedVector, Full)
139+
{
140+
FixedVector<int, 2> vec;
141+
142+
EXPECT_FALSE(vec.full());
143+
vec.push_back(0);
144+
EXPECT_FALSE(vec.full());
145+
vec.push_back(1);
146+
EXPECT_TRUE(vec.full());
147+
}
137148
} // namespace angle

0 commit comments

Comments
 (0)