From b6ba4ac00d1ea86bb1a735391f03fd6ea9e464b1 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Tue, 25 Mar 2014 16:16:57 +0100 Subject: Unduplicate the implementations of next power of two Qtbase contains four identical implementations of next power of two, these should be shared and the implementation made available to other qt modules, as it is also used many places outside of qtbase. [ChangeLog][QtCore][QtMath] Introduced qNextPowerOfTwo methods. Change-Id: Id23fbe5ad6bae647b30d5a4212c0330e48a50278 Reviewed-by: Thiago Macieira --- src/corelib/tools/qbytearray.cpp | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) (limited to 'src/corelib/tools') diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp index 7ca47961c0..52af67c86a 100644 --- a/src/corelib/tools/qbytearray.cpp +++ b/src/corelib/tools/qbytearray.cpp @@ -48,6 +48,7 @@ #include "qlocale_p.h" #include "qscopedpointer.h" #include +#include #ifndef QT_NO_COMPRESS #include @@ -72,19 +73,7 @@ int qAllocMore(int alloc, int extra) Q_DECL_NOTHROW Q_ASSERT(alloc >= 0 && extra >= 0); Q_ASSERT_X(alloc < (1 << 30) - extra, "qAllocMore", "Requested size is too large!"); - unsigned nalloc = alloc + extra; - - // Round up to next power of 2 - - // Assuming container is growing, always overshoot - //--nalloc; - - nalloc |= nalloc >> 1; - nalloc |= nalloc >> 2; - nalloc |= nalloc >> 4; - nalloc |= nalloc >> 8; - nalloc |= nalloc >> 16; - ++nalloc; + unsigned nalloc = qNextPowerOfTwo(alloc + extra); Q_ASSERT(nalloc > unsigned(alloc + extra)); -- cgit v1.2.3