(svn r19473) -Codechange: remove unused variables in the Blob::SmartAlloc code (skidd13)

This commit is contained in:
yexo 2010-03-19 20:28:28 +00:00
parent 787ccc692c
commit aaa8fc7a4c
1 changed files with 13 additions and 14 deletions

View File

@ -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 */