Skip to content

Commit 96fd868

Browse files
author
Alexey Samsonov
committed
Move business logic outside of LIBC_ASSERT, so that it's not optimized away.
1 parent 18db344 commit 96fd868

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

libc/src/__support/fixedvector.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,24 @@ template <typename T, size_t CAPACITY> class FixedVector {
2929
using iterator = typename cpp::array<T, CAPACITY>::iterator;
3030
LIBC_INLINE constexpr FixedVector(iterator begin, iterator end)
3131
: store{}, item_count{} {
32+
LIBC_ASSERT(begin + CAPACITY >= end);
3233
for (; begin != end; ++begin)
33-
LIBC_ASSERT(push_back(*begin));
34+
push_back(*begin);
3435
}
3536

3637
using const_iterator = typename cpp::array<T, CAPACITY>::const_iterator;
3738
LIBC_INLINE constexpr FixedVector(const_iterator begin, const_iterator end)
3839
: store{}, item_count{} {
40+
LIBC_ASSERT(begin + CAPACITY >= end);
3941
for (; begin != end; ++begin)
40-
LIBC_ASSERT(push_back(*begin));
42+
push_back(*begin);
4143
}
4244

4345
LIBC_INLINE constexpr FixedVector(size_t count, const T &value)
4446
: store{}, item_count{} {
47+
LIBC_ASSERT(count <= CAPACITY);
4548
for (size_t i = 0; i < count; ++i)
46-
LIBC_ASSERT(push_back(value));
49+
push_back(value);
4750
}
4851

4952
LIBC_INLINE constexpr bool push_back(const T &obj) {

0 commit comments

Comments
 (0)