mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-16 00:12:51 +00:00
(svn r19473) -Codechange: remove unused variables in the Blob::SmartAlloc code (skidd13)
This commit is contained in:
parent
e0187a0ea5
commit
762fbc70c0
@ -237,25 +237,24 @@ public:
|
|||||||
/** reallocate blob data if needed */
|
/** reallocate blob data if needed */
|
||||||
void SmartAlloc(uint new_size)
|
void SmartAlloc(uint new_size)
|
||||||
{
|
{
|
||||||
uint old_max_size = Capacity();
|
if (Capacity() >= new_size) return;
|
||||||
if (old_max_size >= new_size) return;
|
/* calculate minimum block size we need to allocate
|
||||||
/* calculate minimum block size we need to allocate */
|
* and ask allocation policy for some reasonable block size */
|
||||||
uint min_alloc_size = header_size + new_size + tail_reserve;
|
new_size = AllocPolicy(header_size + new_size + tail_reserve);
|
||||||
/* ask allocation policy for some reasonable block size */
|
|
||||||
uint alloc_size = AllocPolicy(min_alloc_size);
|
/* allocate new block and setup header */
|
||||||
/* allocate new block */
|
BlobHeader *tmp = RawAlloc(new_size);
|
||||||
BlobHeader *tmp = RawAlloc(alloc_size);
|
|
||||||
/* setup header */
|
|
||||||
tmp->items = Length();
|
tmp->items = Length();
|
||||||
tmp->capacity = alloc_size - (header_size + tail_reserve);
|
tmp->capacity = new_size - (header_size + tail_reserve);
|
||||||
|
|
||||||
/* copy existing data */
|
/* copy existing data */
|
||||||
if (Length() > 0)
|
if (tmp->items != 0)
|
||||||
memcpy(tmp + 1, data, tmp->items);
|
memcpy(tmp + 1, data, tmp->items);
|
||||||
|
|
||||||
/* replace our block with new one */
|
/* replace our block with new one */
|
||||||
BlobHeader *pOldHdr = &Hdr();
|
if (Capacity() > 0)
|
||||||
|
RawFree(&Hdr());
|
||||||
Init(tmp);
|
Init(tmp);
|
||||||
if (old_max_size > 0)
|
|
||||||
RawFree(pOldHdr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** fixing the four bytes at the end of blob data - useful when blob is used to hold string */
|
/** fixing the four bytes at the end of blob data - useful when blob is used to hold string */
|
||||||
|
Loading…
Reference in New Issue
Block a user