mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-18 21:19:31 +03:00
Replace power of 2 checks with inline functions
This commit is contained in:
parent
095a87be2e
commit
e8f0375a3b
2 changed files with 2 additions and 2 deletions
|
@ -170,7 +170,7 @@ static inline uintptr_t _mi_is_power_of_two(uintptr_t x) {
|
|||
}
|
||||
static inline uintptr_t _mi_align_up(uintptr_t sz, size_t alignment) {
|
||||
uintptr_t mask = alignment - 1;
|
||||
if ((alignment & mask) == 0) { // power of two?
|
||||
if (_mi_is_power_of_two(alignment)) {
|
||||
return ((sz + mask) & ~mask);
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -46,7 +46,7 @@ int mi_posix_memalign(void** p, size_t alignment, size_t size) mi_attr_noexcept
|
|||
// <http://man7.org/linux/man-pages/man3/posix_memalign.3.html>
|
||||
if (p == NULL) return EINVAL;
|
||||
if (alignment % sizeof(void*) != 0) return EINVAL; // natural alignment
|
||||
if ((alignment & (alignment - 1)) != 0) return EINVAL; // not a power of 2
|
||||
if ((_mi_is_power_of_two(alignment) != 0)) return EINVAL;
|
||||
void* q = mi_malloc_aligned(size, alignment);
|
||||
if (q==NULL && size != 0) return ENOMEM;
|
||||
*p = q;
|
||||
|
|
Loading…
Add table
Reference in a new issue