AP_HAL: Improve ByteBuffer::set_size

So it doesn't delete and re-create the buffer if the size
happens to be the same. Still resets the buffer content.
This commit is contained in:
Murilo Belluzzo 2016-06-23 18:43:04 -03:00 committed by Lucas De Marchi
parent e9e31172c0
commit 625f47def7

View File

@ -19,15 +19,19 @@ ByteBuffer::~ByteBuffer(void)
}
/*
caller is responsible for locking in set_size()
* Caller is responsible for locking in set_size()
*/
void ByteBuffer::set_size(uint32_t _size)
{
uint8_t *oldbuf = buf;
uint8_t *oldbuf;
head = tail = 0;
size = _size;
buf = new uint8_t[size];
delete [] oldbuf;
if (_size != size) {
size = _size;
oldbuf = buf;
buf = new uint8_t[size];
delete[] oldbuf;
}
}
uint32_t ByteBuffer::available(void) const