TemporaryBuffer: Clear block pointer list instead of reallocating

The block pointer list may have been relatively large, so no need to
make more garbage. Instead, just clear the list and null out all the
elements.

Another possible motivation: a caller may have provided an inaccurate
estimated size, so the list might have been resized several times. If
the list is reused later for a similarly underestimated workload, this
fix will prevent additional resizing on subsequent usages.

Change-Id: I511675035dcff1117381a46c294cc11aded10893
This commit is contained in:
Dave Borowitz 2015-03-18 12:51:40 -07:00
parent edf4368b0c
commit e3e9e1f003
1 changed files with 4 additions and 6 deletions

View File

@ -291,13 +291,11 @@ public void reset() {
if (overflow != null) {
destroy();
}
if (inCoreLimit < Block.SZ) {
blocks = new ArrayList<Block>(1);
blocks.add(new Block(inCoreLimit));
} else {
if (blocks != null)
blocks.clear();
else
blocks = new ArrayList<Block>(initialBlocks);
blocks.add(new Block());
}
blocks.add(new Block(Math.min(inCoreLimit, Block.SZ)));
}
/**