Skip to content

Commit b84e0c4

Browse files
committed
modify the branch judgement of the last allocator using const var
1 parent 92c3499 commit b84e0c4

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

ACE/ace/Malloc_T.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,16 +231,18 @@ ACE_Cascaded_Dynamic_Cached_Allocator<ACE_LOCK>::malloc (size_t nbytes)
231231
if (ptr != nullptr)
232232
return ptr;
233233

234-
if (size > 1)
234+
// The code will possibly be optimized by compiler when using const var.
235+
size_t const lastAllocatorPos = size - 1;
236+
if (lastAllocatorPos > 0)
235237
{
236-
ptr = this->hierarchy_[size - 1]->malloc (nbytes);
238+
ptr = this->hierarchy_[lastAllocatorPos]->malloc (nbytes);
237239
if (ptr != nullptr)
238240
return ptr;
239241
}
240242

241243
// Need alloc a new child allocator.
242244
comb_alloc_ptr tmp;
243-
ACE_NEW_RETURN (tmp, comb_alloc_type (this->initial_n_chunks_ * (1 << this->hierarchy_.size()),
245+
ACE_NEW_RETURN (tmp, comb_alloc_type (this->initial_n_chunks_ * (1 << size),
244246
this->chunk_size_),
245247
nullptr);
246248

0 commit comments

Comments
 (0)