summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoryexo <yexo@openttd.org>2010-03-19 20:28:28 +0000
committeryexo <yexo@openttd.org>2010-03-19 20:28:28 +0000
commitaaa8fc7a4c890c5fb04c8d4d97e8846cebe398b9 (patch)
treeb83d0c386599f652d2ca3a41d7f3208ffd4d0012 /src
parent787ccc692c6ade5cf923e54245914a4440088800 (diff)
downloadopenttd-aaa8fc7a4c890c5fb04c8d4d97e8846cebe398b9.tar.xz
(svn r19473) -Codechange: remove unused variables in the Blob::SmartAlloc code (skidd13)
Diffstat (limited to 'src')
-rw-r--r--src/misc/blob.hpp27
1 files changed, 13 insertions, 14 deletions
diff --git a/src/misc/blob.hpp b/src/misc/blob.hpp
index 25d84e050..264366b40 100644
--- a/src/misc/blob.hpp
+++ b/src/misc/blob.hpp
@@ -237,25 +237,24 @@ public:
/** reallocate blob data if needed */
void SmartAlloc(uint new_size)
{
- uint old_max_size = Capacity();
- if (old_max_size >= new_size) return;
- /* calculate minimum block size we need to allocate */
- uint min_alloc_size = header_size + new_size + tail_reserve;
- /* ask allocation policy for some reasonable block size */
- uint alloc_size = AllocPolicy(min_alloc_size);
- /* allocate new block */
- BlobHeader *tmp = RawAlloc(alloc_size);
- /* setup header */
+ if (Capacity() >= new_size) return;
+ /* calculate minimum block size we need to allocate
+ * and ask allocation policy for some reasonable block size */
+ new_size = AllocPolicy(header_size + new_size + tail_reserve);
+
+ /* allocate new block and setup header */
+ BlobHeader *tmp = RawAlloc(new_size);
tmp->items = Length();
- tmp->capacity = alloc_size - (header_size + tail_reserve);
+ tmp->capacity = new_size - (header_size + tail_reserve);
+
/* copy existing data */
- if (Length() > 0)
+ if (tmp->items != 0)
memcpy(tmp + 1, data, tmp->items);
+
/* replace our block with new one */
- BlobHeader *pOldHdr = &Hdr();
+ if (Capacity() > 0)
+ RawFree(&Hdr());
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 */