diff options
author | Arsentiy Milchakov <milcars@mapswithme.com> | 2017-03-23 14:50:19 +0300 |
---|---|---|
committer | Arsentiy Milchakov <milcars@mapswithme.com> | 2017-03-23 14:50:19 +0300 |
commit | 4b1318238b1b7544d1156e9525b85f654ba2dc2d (patch) | |
tree | 659373b72d9af6233c5772d9c02a41a4450ce1bb /base | |
parent | 431299e98329b863b2518ed863c918bc0501256d (diff) |
review fixes
Diffstat (limited to 'base')
-rw-r--r-- | base/base_tests/buffer_vector_test.cpp | 7 | ||||
-rw-r--r-- | base/buffer_vector.hpp | 12 |
2 files changed, 10 insertions, 9 deletions
diff --git a/base/base_tests/buffer_vector_test.cpp b/base/base_tests/buffer_vector_test.cpp index b63d8b08b5..6b7949d488 100644 --- a/base/base_tests/buffer_vector_test.cpp +++ b/base/base_tests/buffer_vector_test.cpp @@ -3,6 +3,7 @@ #include "base/buffer_vector.hpp" #include "base/string_utils.hpp" +#include "std/numeric.hpp" #include "std/unique_ptr.hpp" namespace @@ -152,8 +153,7 @@ UNIT_TEST(BufferVectorInsert) } std::vector<int> dataToInsert(insertLength); - for (size_t i = 0; i < insertLength; ++i) - dataToInsert[i] = 'a' + static_cast<int>(i); + std::iota(dataToInsert.begin(), dataToInsert.end(), 'a'); b.insert(b.begin() + insertPos, dataToInsert.begin(), dataToInsert.end()); v.insert(v.begin() + insertPos, dataToInsert.begin(), dataToInsert.end()); @@ -210,8 +210,7 @@ UNIT_TEST(BufferVectorAppend) } std::vector<int> dataToInsert(insertLength); - for (size_t i = 0; i < insertLength; ++i) - dataToInsert[i] = 'a' + static_cast<int>(i); + std::iota(dataToInsert.begin(), dataToInsert.end(), 'a'); b.append(dataToInsert.begin(), dataToInsert.end()); v.insert(v.end(), dataToInsert.begin(), dataToInsert.end()); diff --git a/base/buffer_vector.hpp b/base/buffer_vector.hpp index e3565e6a26..2da0a75347 100644 --- a/base/buffer_vector.hpp +++ b/base/buffer_vector.hpp @@ -1,5 +1,6 @@ #pragma once #include "base/assert.hpp" +#include "base/checked_cast.hpp" #include "base/stl_iterator.hpp" #include <algorithm> @@ -371,9 +372,8 @@ public: template <typename TIt> void insert(const_iterator where, TIt beg, TIt end) { - ptrdiff_t const pos = where - data(); - ASSERT_GREATER_OR_EQUAL(pos, 0, ()); - ASSERT_LESS_OR_EQUAL(pos, static_cast<ptrdiff_t>(size()), ()); + size_t const pos = base::asserted_cast<size_t>(where - data()); + ASSERT_LESS_OR_EQUAL(pos, size(), ()); if (IsDynamic()) { @@ -384,9 +384,11 @@ public: size_t const n = end - beg; if (m_size + n <= N) { - if (static_cast<size_t>(pos) != m_size) - for (ptrdiff_t i = m_size - 1; i >= pos; --i) + if (pos != m_size) + { + for (size_t i = m_size - 1; i >= pos && i < m_size; --i) Swap(m_static[i], m_static[i + n]); + } m_size += n; T * writableWhere = &m_static[0] + pos; |