From 137a52ccf7bb5f84c338a614011897a4e4548521 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Fri, 16 Oct 2015 09:02:39 -0700 Subject: [PATCH] Merged latest tintystl. --- include/tinystl/buffer.h | 22 ++++++++++++++++++++++ include/tinystl/vector.h | 12 +++++------- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/include/tinystl/buffer.h b/include/tinystl/buffer.h index 5fac229..4351ec2 100644 --- a/include/tinystl/buffer.h +++ b/include/tinystl/buffer.h @@ -179,9 +179,11 @@ namespace tinystl { Alloc::static_deallocate(b->first, sizeof(T)*capacity); b->capacity = b->first; } else if (b->capacity != b->last) { + const size_t capacity = (size_t)(b->capacity - b->first); const size_t size = (size_t)(b->last - b->first); T* newfirst = (T*)Alloc::static_allocate(sizeof(T) * size); buffer_move_urange(newfirst, b->first, b->last); + Alloc::static_deallocate(b->first, sizeof(T) * capacity); b->first = newfirst; b->last = newfirst + size; b->capacity = b->last; @@ -225,6 +227,26 @@ namespace tinystl { new(placeholder(), where) T(); } + template + static inline void buffer_append(buffer* b, const Param* param) { + if (b->capacity != b->last) { + new(placeholder(), b->last) T(*param); + ++b->last; + } else { + buffer_insert(b, b->last, param, param + 1); + } + } + + template + static inline void buffer_append(buffer* b) { + if (b->capacity != b->last) { + new(placeholder(), b->last) T(); + ++b->last; + } else { + buffer_insert(b, b->last, 1); + } + } + template static inline T* buffer_erase(buffer* b, T* first, T* last) { typedef T* pointer; diff --git a/include/tinystl/vector.h b/include/tinystl/vector.h index 96fe1b4..6885feb 100644 --- a/include/tinystl/vector.h +++ b/include/tinystl/vector.h @@ -228,20 +228,18 @@ namespace tinystl { template inline void vector::push_back(const T& t) { - buffer_insert(&m_buffer, m_buffer.last, &t, &t + 1); + buffer_append(&m_buffer, &t); } template - inline void vector::emplace_back() - { - buffer_insert(&m_buffer, m_buffer.last, 1); + inline void vector::emplace_back() { + buffer_append(&m_buffer); } template template - inline void vector::emplace_back(const Param& param) - { - buffer_insert(&m_buffer, m_buffer.last, ¶m, ¶m + 1); + inline void vector::emplace_back(const Param& param) { + buffer_append(&m_buffer, ¶m); } template