summaryrefslogtreecommitdiff
path: root/src/queue.cpp
diff options
context:
space:
mode:
authorKUDr <kudr@openttd.org>2007-01-11 17:29:39 +0000
committerKUDr <kudr@openttd.org>2007-01-11 17:29:39 +0000
commit33be1ecfb1a9056b027d50d7b558cff87c5b744d (patch)
treed644a3831ca0947198b191fa3e4e8973d3a9786e /src/queue.cpp
parent91ff74641060445dc1647bbf05baeb03b45c3099 (diff)
downloadopenttd-33be1ecfb1a9056b027d50d7b558cff87c5b744d.tar.xz
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
Diffstat (limited to 'src/queue.cpp')
-rw-r--r--src/queue.cpp31
1 files changed, 12 insertions, 19 deletions
diff --git a/src/queue.cpp b/src/queue.cpp
index 44ace52e5..b371908e0 100644
--- a/src/queue.cpp
+++ b/src/queue.cpp
@@ -49,15 +49,14 @@ static Queue* init_stack(Queue* q, uint max_size)
q->free = Stack_Free;
q->data.stack.max_size = max_size;
q->data.stack.size = 0;
- MallocT(&q->data.stack.elements, max_size);
+ q->data.stack.elements = MallocT<void*>(max_size);
q->freeq = false;
return q;
}
Queue* new_Stack(uint max_size)
{
- Queue* q;
- MallocT(&q, 1);
+ Queue* q = MallocT<Queue>(1);
init_stack(q, max_size);
q->freeq = true;
@@ -127,16 +126,14 @@ static Queue* init_fifo(Queue* q, uint max_size)
q->data.fifo.max_size = max_size;
q->data.fifo.head = 0;
q->data.fifo.tail = 0;
- MallocT(&q->data.fifo.elements, max_size);
+ q->data.fifo.elements = MallocT<void*>(max_size);
q->freeq = false;
return q;
}
Queue* new_Fifo(uint max_size)
{
- Queue* q;
- MallocT(&q, 1);
-
+ Queue* q = MallocT<Queue>(1);
init_fifo(q, max_size);
q->freeq = true;
return q;
@@ -169,8 +166,7 @@ static void InsSort_Free(Queue* q, bool free_values)
static bool InsSort_Push(Queue* q, void* item, int priority)
{
- InsSortNode* newnode;
- MallocT(&newnode, 1);
+ InsSortNode* newnode = MallocT<InsSortNode>(1);
if (newnode == NULL) return false;
newnode->item = item;
@@ -224,8 +220,7 @@ void init_InsSort(Queue* q)
Queue* new_InsSort(void)
{
- Queue* q;
- MallocT(&q, 1);
+ Queue* q = MallocT<Queue>(1);
init_InsSort(q);
q->freeq = true;
@@ -304,7 +299,7 @@ static bool BinaryHeap_Push(Queue* q, void* item, int priority)
if (q->data.binaryheap.elements[q->data.binaryheap.size >> BINARY_HEAP_BLOCKSIZE_BITS] == NULL) {
/* The currently allocated blocks are full, allocate a new one */
assert((q->data.binaryheap.size & BINARY_HEAP_BLOCKSIZE_MASK) == 0);
- MallocT(&q->data.binaryheap.elements[q->data.binaryheap.size >> BINARY_HEAP_BLOCKSIZE_BITS], BINARY_HEAP_BLOCKSIZE);
+ q->data.binaryheap.elements[q->data.binaryheap.size >> BINARY_HEAP_BLOCKSIZE_BITS] = MallocT<BinaryHeapNode>(BINARY_HEAP_BLOCKSIZE);
q->data.binaryheap.blocks++;
#ifdef QUEUE_DEBUG
printf("[BinaryHeap] Increasing size of elements to %d nodes\n", q->data.binaryheap.blocks * BINARY_HEAP_BLOCKSIZE);
@@ -432,8 +427,8 @@ void init_BinaryHeap(Queue* q, uint max_size)
q->data.binaryheap.size = 0;
// We malloc memory in block of BINARY_HEAP_BLOCKSIZE
// It autosizes when it runs out of memory
- CallocT(&q->data.binaryheap.elements, (max_size - 1) / BINARY_HEAP_BLOCKSIZE + 1);
- MallocT(&q->data.binaryheap.elements[0], BINARY_HEAP_BLOCKSIZE);
+ q->data.binaryheap.elements = CallocT<BinaryHeapNode*>((max_size - 1) / BINARY_HEAP_BLOCKSIZE + 1);
+ q->data.binaryheap.elements[0] = MallocT<BinaryHeapNode>(BINARY_HEAP_BLOCKSIZE);
q->data.binaryheap.blocks = 1;
q->freeq = false;
#ifdef QUEUE_DEBUG
@@ -443,8 +438,7 @@ void init_BinaryHeap(Queue* q, uint max_size)
Queue* new_BinaryHeap(uint max_size)
{
- Queue* q;
- MallocT(&q, 1);
+ Queue* q = MallocT<Queue>(1);
init_BinaryHeap(q, max_size);
q->freeq = true;
@@ -481,8 +475,7 @@ void init_Hash(Hash* h, Hash_HashProc* hash, uint num_buckets)
Hash* new_Hash(Hash_HashProc* hash, int num_buckets)
{
- Hash* h;
- MallocT(&h, 1);
+ Hash* h = MallocT<Hash>(1);
init_Hash(h, hash, num_buckets);
h->freeh = true;
@@ -716,7 +709,7 @@ void* Hash_Set(Hash* h, uint key1, uint key2, void* value)
node = h->buckets + hash;
} else {
/* Add it after prev */
- MallocT(&node, 1);
+ node = MallocT<HashNode>(1);
prev->next = node;
}
node->next = NULL;