Skip to content

Commit d6a0912

Browse files
author
Sergey Oblomov
committed
OSHMEM: minor optimization of realloc in shadow allocator
Signed-off-by: Sergey Oblomov <sergeyo@mellanox.com>
1 parent a51badd commit d6a0912

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

oshmem/mca/sshmem/ucx/sshmem_ucx_shadow.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,10 @@ int sshmem_ucx_shadow_realloc(sshmem_ucx_shadow_allocator_t *allocator,
113113
unsigned count, unsigned old_index, unsigned *index,
114114
int *inplace)
115115
{
116-
sshmem_ucx_shadow_alloc_elem_t *end = &allocator->elems[allocator->num_elems];
117116
sshmem_ucx_shadow_alloc_elem_t *elem = &allocator->elems[old_index];
118-
sshmem_ucx_shadow_alloc_elem_t *next = &elem[elem->block_size];
119117
unsigned old_count = elem->block_size;
118+
sshmem_ucx_shadow_alloc_elem_t *end;
119+
sshmem_ucx_shadow_alloc_elem_t *next;
120120

121121
assert(count > 0);
122122
assert(!sshmem_ucx_shadow_is_free(elem));
@@ -142,8 +142,10 @@ int sshmem_ucx_shadow_realloc(sshmem_ucx_shadow_allocator_t *allocator,
142142

143143
assert(count > old_count);
144144

145+
end = &allocator->elems[allocator->num_elems];
146+
next = &elem[old_count];
145147
/* try to check if next element is free & has enough length */
146-
if ((next < end) && /* non-last element? */
148+
if ((next < end) && /* non-last element? */
147149
sshmem_ucx_shadow_is_free(next) && /* next is free */
148150
(old_count + next->block_size >= count))
149151
{

0 commit comments

Comments
 (0)