You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

small_vector.cpp 1.1 kB

1234567891011121314151617181920212223242526272829303132
  1. #include "megdnn/thin/small_vector.h"
  2. #include "src/common/utils.h"
  3. using namespace megdnn;
  4. void SmallVectorBase::on_invalid_at(size_t idx, size_t size) {
  5. megdnn_throw(ssprintf("invalid vector at(): idx=%zu size=%zu", idx, size));
  6. MEGDNN_MARK_USED_VAR(idx);
  7. MEGDNN_MARK_USED_VAR(size);
  8. }
  9. void SmallVectorBase::grow_pod(
  10. void* first_elm_ptr, size_t min_sz_in_bytes, size_t type_size) {
  11. size_t cur_sz_in_bytes = size_in_bytes();
  12. size_t new_capacity_in_bytes = 2 * capacity_in_bytes() + type_size;
  13. if (new_capacity_in_bytes < min_sz_in_bytes) {
  14. new_capacity_in_bytes = min_sz_in_bytes;
  15. }
  16. void* new_begin;
  17. if (first_elm_ptr == m_begin_ptr) {
  18. new_begin = malloc(new_capacity_in_bytes);
  19. memcpy(new_begin, m_begin_ptr, cur_sz_in_bytes);
  20. } else {
  21. new_begin = realloc(this->m_begin_ptr, new_capacity_in_bytes);
  22. }
  23. this->m_begin_ptr = new_begin;
  24. this->m_end_ptr = static_cast<char*>(this->m_begin_ptr) + cur_sz_in_bytes;
  25. this->m_capacity_ptr =
  26. static_cast<char*>(this->m_begin_ptr) + new_capacity_in_bytes;
  27. }
  28. // vim: syntax=cpp.doxygen