From f39c2d5e70a8a26680b7be6916a488efb630cd29 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Mon, 25 Sep 2017 23:01:22 +0200 Subject: [PATCH] Fix tracy::Vector::insert(). --- server/TracyVector.hpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/server/TracyVector.hpp b/server/TracyVector.hpp index e9869f63..36b61315 100755 --- a/server/TracyVector.hpp +++ b/server/TracyVector.hpp @@ -76,22 +76,26 @@ public: m_ptr[m_size++] = std::move( v ); } - void insert( T* it, const T& v ) + T* insert( T* it, const T& v ) { assert( it >= m_ptr && it <= m_ptr + m_size ); + const auto dist = it - m_ptr; if( m_size == m_capacity ) AllocMore(); - if( it != m_ptr + m_size ) memmove( it+1, it, ( m_size - ( it - m_ptr ) ) * sizeof( T ) ); + if( dist != m_size ) memmove( m_ptr + dist + 1, m_ptr + dist, ( m_size - dist ) * sizeof( T ) ); m_size++; - *it = v; + m_ptr[dist] = v; + return m_ptr + dist; } - void insert( T* it, T&& v ) + T* insert( T* it, T&& v ) { assert( it >= m_ptr && it <= m_ptr + m_size ); + const auto dist = it - m_ptr; if( m_size == m_capacity ) AllocMore(); - if( it != m_ptr + m_size ) memmove( it+1, it, ( m_size - ( it - m_ptr ) ) * sizeof( T ) ); + if( dist != m_size ) memmove( m_ptr + dist + 1, m_ptr + dist, ( m_size - dist ) * sizeof( T ) ); m_size++; - *it = std::move( v ); + m_ptr[dist] = std::move( v ); + return m_ptr + dist; } private: