40 for (
int i = 0; i < _allocatedBlocks; ++i) {
41 if (
char *b = _blocks[i])
51 size = (size + 7) & ~size_t(7);
52 if (Q_LIKELY(_ptr && size < size_t(_end - _ptr))) {
57 return allocate_helper(size);
63 _ptr = _end =
nullptr;
66 template <
typename Tp> Tp *
New() {
return new (
this->allocate(
sizeof(Tp))) Tp(); }
67 template <
typename Tp,
typename... Ta> Tp *
New(Ta... args)
68 {
return new (
this->allocate(
sizeof(Tp))) Tp(args...); }
71 return strings.emplace_back(std::move(string));
75 Q_NEVER_INLINE
void *allocate_helper(size_t size)
77 size_t currentBlockSize = DEFAULT_BLOCK_SIZE;
78 while (Q_UNLIKELY(size >= currentBlockSize))
79 currentBlockSize *= 2;
81 if (++_blockCount == _allocatedBlocks) {
82 if (! _allocatedBlocks)
83 _allocatedBlocks = DEFAULT_BLOCK_COUNT;
85 _allocatedBlocks *= 2;
87 _blocks =
reinterpret_cast<
char **>(realloc(_blocks,
sizeof(
char *) * size_t(_allocatedBlocks)));
90 for (
int index = _blockCount; index < _allocatedBlocks; ++index)
91 _blocks[index] =
nullptr;
94 char *&block = _blocks[_blockCount];
97 block =
reinterpret_cast<
char *>(malloc(currentBlockSize));
102 _end = _ptr + currentBlockSize;
110 char **_blocks =
nullptr;
111 int _allocatedBlocks = 0;
112 int _blockCount = -1;
113 char *_ptr =
nullptr;
114 char *_end =
nullptr;
119 DEFAULT_BLOCK_SIZE = 8 * 1024,
120 DEFAULT_BLOCK_COUNT = 8