Skip to content

Commit

Permalink
better resize implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
KRM7 committed Mar 15, 2024
1 parent 711dec0 commit 87a1bcd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion benchmark/small_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void benchmark_resize(benchmark::State& state)

for (auto _ : state)
{
vec.resize(size - 1);
vec.resize(0);
benchmark::DoNotOptimize(vec);

vec.resize(size);
Expand Down
4 changes: 2 additions & 2 deletions src/small_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -978,12 +978,12 @@ class small_vector
template<typename... Args>
constexpr void resize_impl(size_type count, Args&&... args)
{
if (count < size())
if (count <= size())
{
detail::destroy_range(alloc_, first_ + count, last_);
last_ = first_ + count;
}
else if (count > size())
else
{
reserve(count);
detail::construct_range(alloc_, last_, first_ + count, std::forward<Args>(args)...);
Expand Down

0 comments on commit 87a1bcd

Please sign in to comment.