MCPcopy Create free account
hub / github.com/apache/trafficserver / enlargeBuffer

Method enlargeBuffer

src/tscore/TextBuffer.cc:124–151  ·  view source on GitHub ↗

TextBuffer::enlargeBuffer(int n) Enlarge the buffer so at least at N bytes are free in the buffer. Always enlarges by a power of two. Returns -1 if insufficient memory, zero otherwise

Source from the content-addressed store, hash-verified

122// Returns -1 if insufficient memory,
123// zero otherwise
124int
125TextBuffer::enlargeBuffer(unsigned N)
126{
127 unsigned addedSize = 0;
128 unsigned newSize = (currentSize ? currentSize : 1) * 2;
129 char *newSpace;
130
131 if (spaceLeft < N) {
132 while ((newSize - currentSize) < N) {
133 newSize *= 2;
134 }
135
136 addedSize = newSize - currentSize;
137
138 newSpace = static_cast<char *>(ats_realloc(bufferStart, newSize));
139 if (newSpace != nullptr) {
140 nextAdd = newSpace + static_cast<unsigned>(nextAdd - bufferStart);
141 bufferStart = newSpace;
142 spaceLeft += addedSize;
143 currentSize = newSize;
144 } else {
145 // Out of Memory, Sigh
146 return -1;
147 }
148 }
149
150 return 0;
151}
152
153// int TextBuffer::rawReadFromFile
154//

Callers 1

resizeMethod · 0.95

Calls 1

ats_reallocFunction · 0.85

Tested by

no test coverage detected