39 for (
int i = 0; i < _allocatedBlocks; ++i) {
40 if (
char *b = _blocks[i])
50 size = (size + 7) & ~size_t(7);
51 if (Q_LIKELY(_ptr && size < size_t(_end - _ptr))) {
56 return allocate_helper(size);
62 _ptr = _end =
nullptr;
65 template <
typename Tp> Tp *
New() {
return new (
this->allocate(
sizeof(Tp))) Tp(); }
66 template <
typename Tp,
typename... Ta> Tp *
New(Ta... args)
67 {
return new (
this->allocate(
sizeof(Tp))) Tp(args...); }
70 return strings.emplace_back(std::move(string));
74 Q_NEVER_INLINE
void *allocate_helper(size_t size)
76 size_t currentBlockSize = DEFAULT_BLOCK_SIZE;
77 while (Q_UNLIKELY(size >= currentBlockSize))
78 currentBlockSize *= 2;
80 if (++_blockCount == _allocatedBlocks) {
81 if (! _allocatedBlocks)
82 _allocatedBlocks = DEFAULT_BLOCK_COUNT;
84 _allocatedBlocks *= 2;
86 _blocks =
reinterpret_cast<
char **>(realloc(_blocks,
sizeof(
char *) * size_t(_allocatedBlocks)));
89 for (
int index = _blockCount; index < _allocatedBlocks; ++index)
90 _blocks[index] =
nullptr;
93 char *&block = _blocks[_blockCount];
96 block =
reinterpret_cast<
char *>(malloc(currentBlockSize));
101 _end = _ptr + currentBlockSize;
109 char **_blocks =
nullptr;
110 int _allocatedBlocks = 0;
111 int _blockCount = -1;
112 char *_ptr =
nullptr;
113 char *_end =
nullptr;
118 DEFAULT_BLOCK_SIZE = 8 * 1024,
119 DEFAULT_BLOCK_COUNT = 8