MCPcopy Create free account
hub / github.com/apache/tomcat / makeSpace

Method makeSpace

java/org/apache/tomcat/util/buf/CharChunk.java:396–434  ·  view source on GitHub ↗

Make space for len chars. If len is small, allocate a reserve space too. Never grow bigger than the limit or AbstractChunk#ARRAY_MAX_SIZE. @param count The size

(int count)

Source from the content-addressed store, hash-verified

394 * @param count The size
395 */
396 public void makeSpace(int count) {
397 int limit = getLimitInternal();
398
399 long newSize;
400 long desiredSize = end + count;
401
402 // Can't grow above the limit
403 if (desiredSize > limit) {
404 desiredSize = limit;
405 }
406
407 if (buff == null) {
408 if (desiredSize < 256) {
409 desiredSize = 256; // take a minimum
410 }
411 buff = new char[(int) desiredSize];
412 }
413
414 // limit < buf.length (the buffer is already big)
415 // or we already have space
416 if (desiredSize <= buff.length) {
417 return;
418 }
419 // grow in larger chunks
420 if (desiredSize < 2L * buff.length) {
421 newSize = buff.length * 2L;
422 } else {
423 newSize = buff.length * 2L + count;
424 }
425
426 if (newSize > limit) {
427 newSize = limit;
428 }
429 char[] tmp = new char[(int) newSize];
430
431 // Some calling code assumes buffer will not be compacted
432 System.arraycopy(buff, 0, tmp, 0, end);
433 buff = tmp;
434 }
435
436
437 // -------------------- Conversion and getters --------------------

Callers 2

testLeftoverChunkMethod · 0.95
appendMethod · 0.95

Calls 1

getLimitInternalMethod · 0.80

Tested by 1

testLeftoverChunkMethod · 0.76