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:
parent
e9e31172c0
commit
625f47def7
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user