From b6f9a19193b1de7cfef8ab3328cde6028a2d19d7 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Thu, 9 Oct 2008 12:00:45 +0000 Subject: [PATCH] re-use a pre-allocated stack. PR 45960. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@703146 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tools/bzip2/CBZip2OutputStream.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/org/apache/tools/bzip2/CBZip2OutputStream.java b/src/main/org/apache/tools/bzip2/CBZip2OutputStream.java index bb01eb4ac..b2ad87e09 100644 --- a/src/main/org/apache/tools/bzip2/CBZip2OutputStream.java +++ b/src/main/org/apache/tools/bzip2/CBZip2OutputStream.java @@ -999,13 +999,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { int dd; } - private void qSort3(int loSt, int hiSt, int dSt) { + private void qSort3(int loSt, int hiSt, int dSt, StackElem[] stack) { int unLo, unHi, ltLo, gtHi, med, n, m; int sp, lo, hi, d; - StackElem[] stack = new StackElem[QSORT_STACK_SIZE]; - for (int count = 0; count < QSORT_STACK_SIZE; count++) { - stack[count] = new StackElem(); - } sp = 0; @@ -1228,6 +1224,11 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { } while (h != 1); } + StackElem[] stack = new StackElem[QSORT_STACK_SIZE]; + for (int count = 0; count < QSORT_STACK_SIZE; count++) { + stack[count] = new StackElem(); + } + /* The main sorting loop. */ @@ -1251,7 +1252,7 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { int lo = ftab[sb] & CLEARMASK; int hi = (ftab[sb + 1] & CLEARMASK) - 1; if (hi > lo) { - qSort3(lo, hi, 2); + qSort3(lo, hi, 2, stack); numQSorted += (hi - lo + 1); if (workDone > workLimit && firstAttempt) { return;