Qt 4.8
Functions
qtools_p.h File Reference
#include "QtCore/qglobal.h"

Go to the source code of this file.

Functions

int Q_CORE_EXPORT qAllocMore (int alloc, int extra)
 

Function Documentation

◆ qAllocMore()

int Q_CORE_EXPORT qAllocMore ( int  alloc,
int  extra 
)

Definition at line 70 of file qbytearray.cpp.

Referenced by QByteArray::append(), QFragmentMapData< QTextBlockData >::createFragment(), grow(), QVectorData::grow(), QString::grow(), and QByteArray::prepend().

71 {
72  Q_ASSERT(alloc >= 0 && extra >= 0);
73  Q_ASSERT_X(alloc < (1 << 30) - extra, "qAllocMore", "Requested size is too large!");
74 
75  if (alloc == 0 && extra == 0)
76  return 0;
77  const int page = 1 << 12;
78  int nalloc;
79  alloc += extra;
80  if (alloc < 1<<6) {
81  nalloc = (1<<3) + ((alloc >>3) << 3);
82  } else {
83  // don't do anything if the loop will overflow signed int.
84  if (alloc >= INT_MAX/2)
85  return INT_MAX;
86  nalloc = (alloc < page) ? 1 << 3 : page;
87  while (nalloc < alloc) {
88  if (nalloc <= 0)
89  return INT_MAX;
90  nalloc *= 2;
91  }
92  }
93  return nalloc - extra;
94 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
#define INT_MAX