Replace modulus with mask operation in over-aligned new

2016-09-16  Jonathan Wakely  <jwakely@redhat.com>
	    Marc Glisse  <marc.glisse@inria.fr>

	* libsupc++/new_opa.cc [_GLIBCXX_HAVE_ALIGNED_ALLOC]
	(operator new(size_t, align_val_t)): Replace modulus operator with
	mask.

Co-Authored-By: Marc Glisse <marc.glisse@inria.fr>

From-SVN: r240192
This commit is contained in:
Jonathan Wakely 2016-09-16 19:09:14 +01:00 committed by Jonathan Wakely
parent 8d987deb5b
commit 84c08ec96a
2 changed files with 8 additions and 1 deletions

View File

@ -1,3 +1,10 @@
2016-09-16 Jonathan Wakely <jwakely@redhat.com>
Marc Glisse <marc.glisse@inria.fr>
* libsupc++/new_opa.cc [_GLIBCXX_HAVE_ALIGNED_ALLOC]
(operator new(size_t, align_val_t)): Replace modulus operator with
mask.
2016-09-16 Jonathan Wakely <jwakely@redhat.com>
* libsupc++/new_opa.cc [_GLIBCXX_HAVE_POSIX_MEMALIGN] (aligned_alloc):

View File

@ -69,7 +69,7 @@ operator new (std::size_t sz, std::align_val_t al)
#if _GLIBCXX_HAVE_ALIGNED_ALLOC
/* C11: the value of size shall be an integral multiple of alignment. */
if (std::size_t rem = sz % align)
if (std::size_t rem = sz & (align - 1))
sz += align - rem;
#endif