10000 MAINT: remove unneeded test in npy_is_aligned · numpy/numpy@12bd7c3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 12bd7c3

Browse files
committed
MAINT: remove unneeded test in npy_is_aligned
1 parent 38af6dd commit 12bd7c3

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

numpy/core/src/multiarray/common.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -197,15 +197,12 @@ static NPY_INLINE int
197197
npy_is_aligned(const void * p, const npy_uintp alignment)
198198
{
199199
/*
200-
* alignment is usually a power of two
201-
* the test is faster than a direct modulo
200+
* Assumes alignment is a power of two, as required by the C standard.
201+
* Assumes cast from pointer to uintp gives a sensible representation we
202+
* can use bitwise & on (not required by C standard, but used by glibc).
203+
* This test is faster than a direct modulo.
202204
*/
203-
if (NPY_LIKELY((alignment & (alignment - 1)) == 0)) {
204-
return ((npy_uintp)(p) & ((alignment) - 1)) == 0;
205-
}
206-
else {
207-
return ((npy_uintp)(p) % alignment) == 0;
208-
}
205+
return ((npy_uintp)(p) & ((alignment) - 1)) == 0;
209206
}
210207

211208
/* Get equivalent "uint" alignment given an itemsize, for use in copy code */

0 commit comments

Comments
 (0)
0