From 1e6707c609f6cadd3b481738ed029520911056af Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 19 Nov 2017 17:27:51 +0100 Subject: [PATCH] Add no-nullptr-check push_back to Vector. --- server/TracyVector.hpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/server/TracyVector.hpp b/server/TracyVector.hpp index 082f4551..d7a30f72 100644 --- a/server/TracyVector.hpp +++ b/server/TracyVector.hpp @@ -79,6 +79,12 @@ public: m_ptr[m_size++] = v; } + void push_back_non_empty( const T& v ) + { + if( m_size == CapacityNoNullptrCheck() ) AllocMore(); + m_ptr[m_size++] = v; + } + void push_back( T&& v ) { if( m_size == Capacity() ) AllocMore(); @@ -186,7 +192,7 @@ private: void Realloc() { - T* ptr = new T[CapacityNew()]; + T* ptr = new T[CapacityNoNullptrCheck()]; if( m_size != 0 ) { memcpy( ptr, m_ptr, m_size * sizeof( T ) ); @@ -200,7 +206,7 @@ private: return m_ptr == nullptr ? 0 : 1 << m_capacity; } - uint32_t CapacityNew() const + uint32_t CapacityNoNullptrCheck() const { return 1 << m_capacity; }