Skip to content

Commit

Permalink
Improving the code
Browse files Browse the repository at this point in the history
In the mpool_alloc and mpool_calloc functions, I observed duplicate code
 segments. Consequently, I refactored the mpool_calloc function. I
consider that removing duplicate code enhances code cleanliness and
facilitates maintainability.
  • Loading branch information
Happy authored and Happy committed May 10, 2024
1 parent c469828 commit d4af1d6
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions src/mpool.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,7 @@ void *mpool_alloc(mpool_t *mp)

void *mpool_calloc(mpool_t *mp)
{
if (!mp->chunk_count && !(mpool_extend(mp)))
return NULL;

char *ptr = (char *) mp->free_chunk_head + sizeof(memchunk_t);
mp->free_chunk_head = mp->free_chunk_head->next;
mp->chunk_count--;
char *ptr = mpool_alloc(mp);
memset(ptr, 0, mp->chunk_size);
return ptr;
}
Expand Down

0 comments on commit d4af1d6

Please sign in to comment.