From e3e9e1f003b09a35048e0c30f8a77c66dcfdda32 Mon Sep 17 00:00:00 2001 From: Dave Borowitz Date: Wed, 18 Mar 2015 12:51:40 -0700 Subject: [PATCH] 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 --- .../src/org/eclipse/jgit/util/TemporaryBuffer.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/TemporaryBuffer.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/TemporaryBuffer.java index 0a8c5945d..006c3c0a0 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/TemporaryBuffer.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/TemporaryBuffer.java @@ -291,13 +291,11 @@ public abstract class TemporaryBuffer extends OutputStream { if (overflow != null) { destroy(); } - if (inCoreLimit < Block.SZ) { - blocks = new ArrayList(1); - blocks.add(new Block(inCoreLimit)); - } else { + if (blocks != null) + blocks.clear(); + else blocks = new ArrayList(initialBlocks); - blocks.add(new Block()); - } + blocks.add(new Block(Math.min(inCoreLimit, Block.SZ))); } /**