Browse Source

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
master
Stefan Bodewig 16 years ago
parent
commit
b6f9a19193
1 changed files with 7 additions and 6 deletions
  1. +7
    -6
      src/main/org/apache/tools/bzip2/CBZip2OutputStream.java

+ 7
- 6
src/main/org/apache/tools/bzip2/CBZip2OutputStream.java View File

@@ -999,13 +999,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
int dd; 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 unLo, unHi, ltLo, gtHi, med, n, m;
int sp, lo, hi, d; 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; sp = 0;


@@ -1228,6 +1224,11 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
} while (h != 1); } 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. The main sorting loop.
*/ */
@@ -1251,7 +1252,7 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
int lo = ftab[sb] & CLEARMASK; int lo = ftab[sb] & CLEARMASK;
int hi = (ftab[sb + 1] & CLEARMASK) - 1; int hi = (ftab[sb + 1] & CLEARMASK) - 1;
if (hi > lo) { if (hi > lo) {
qSort3(lo, hi, 2);
qSort3(lo, hi, 2, stack);
numQSorted += (hi - lo + 1); numQSorted += (hi - lo + 1);
if (workDone > workLimit && firstAttempt) { if (workDone > workLimit && firstAttempt) {
return; return;


Loading…
Cancel
Save