refactored approxpoly
This commit is contained in:
@@ -3107,6 +3107,10 @@ public:
|
||||
void allocate(size_t _size);
|
||||
//! deallocates the buffer if it was dynamically allocated
|
||||
void deallocate();
|
||||
//! resizes the buffer and preserves the content
|
||||
void resize(size_t _size);
|
||||
//! returns the current buffer size
|
||||
size_t size() const;
|
||||
//! returns pointer to the real buffer, stack-allocated or head-allocated
|
||||
operator _Tp* ();
|
||||
//! returns read-only pointer to the real buffer, stack-allocated or head-allocated
|
||||
@@ -3116,7 +3120,7 @@ protected:
|
||||
//! pointer to the real buffer, can point to buf if the buffer is small enough
|
||||
_Tp* ptr;
|
||||
//! size of the real buffer
|
||||
size_t size;
|
||||
size_t sz;
|
||||
//! pre-allocated buffer
|
||||
_Tp buf[fixed_size+buffer_padding];
|
||||
};
|
||||
|
||||
@@ -2537,13 +2537,13 @@ inline Point LineIterator::pos() const
|
||||
template<typename _Tp, size_t fixed_size> inline AutoBuffer<_Tp, fixed_size>::AutoBuffer()
|
||||
{
|
||||
ptr = buf;
|
||||
size = fixed_size;
|
||||
sz = fixed_size;
|
||||
}
|
||||
|
||||
template<typename _Tp, size_t fixed_size> inline AutoBuffer<_Tp, fixed_size>::AutoBuffer(size_t _size)
|
||||
{
|
||||
ptr = buf;
|
||||
size = fixed_size;
|
||||
sz = fixed_size;
|
||||
allocate(_size);
|
||||
}
|
||||
|
||||
@@ -2552,13 +2552,16 @@ template<typename _Tp, size_t fixed_size> inline AutoBuffer<_Tp, fixed_size>::~A
|
||||
|
||||
template<typename _Tp, size_t fixed_size> inline void AutoBuffer<_Tp, fixed_size>::allocate(size_t _size)
|
||||
{
|
||||
if(_size <= size)
|
||||
if(_size <= sz)
|
||||
{
|
||||
sz = _size;
|
||||
return;
|
||||
}
|
||||
deallocate();
|
||||
if(_size > fixed_size)
|
||||
{
|
||||
ptr = cv::allocate<_Tp>(_size);
|
||||
size = _size;
|
||||
ptr = new _Tp[_size];
|
||||
sz = _size;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2566,12 +2569,38 @@ template<typename _Tp, size_t fixed_size> inline void AutoBuffer<_Tp, fixed_size
|
||||
{
|
||||
if( ptr != buf )
|
||||
{
|
||||
cv::deallocate<_Tp>(ptr, size);
|
||||
delete[] ptr;
|
||||
ptr = buf;
|
||||
size = fixed_size;
|
||||
sz = 0;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename _Tp, size_t fixed_size> inline void AutoBuffer<_Tp, fixed_size>::resize(size_t _size)
|
||||
{
|
||||
if(_size <= sz)
|
||||
{
|
||||
sz = _size;
|
||||
return;
|
||||
}
|
||||
size_t i, prevsize = sz, minsize = MIN(prevsize, _size);
|
||||
_Tp* prevptr = ptr;
|
||||
|
||||
ptr = _size > fixed_size ? new _Tp[_size] : buf;
|
||||
sz = _size;
|
||||
|
||||
if( ptr != prevptr )
|
||||
for( i = 0; i < minsize; i++ )
|
||||
ptr[i] = prevptr[i];
|
||||
for( i = prevsize; i < _size; i++ )
|
||||
ptr[i] = _Tp();
|
||||
|
||||
if( prevptr != buf )
|
||||
delete[] prevptr;
|
||||
}
|
||||
|
||||
template<typename _Tp, size_t fixed_size> inline size_t AutoBuffer<_Tp, fixed_size>::size() const
|
||||
{ return sz; }
|
||||
|
||||
template<typename _Tp, size_t fixed_size> inline AutoBuffer<_Tp, fixed_size>::operator _Tp* ()
|
||||
{ return ptr; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user