Skip to content
This repository has been archived by the owner on Jul 21, 2020. It is now read-only.

Android L optimisation #33

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 15 additions & 22 deletions unrar/src/main/java/com/github/junrar/Archive.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
Expand Down Expand Up @@ -461,28 +461,21 @@ public void extractFile(FileHeader hd, OutputStream os) throws RarException {
* @throws IOException
* if any IO error occur
*/
public InputStream getInputStream(final FileHeader hd) throws RarException,
IOException {
final PipedInputStream in = new PipedInputStream(32 * 1024);
final PipedOutputStream out = new PipedOutputStream(in);

// creates a new thread that will write data to the pipe. Data will be
// available in another InputStream, connected to the OutputStream.
new Thread(new Runnable() {
public void run() {
try {
extractFile(hd, out);
} catch (RarException e) {
} finally {
try {
out.close();
} catch (IOException e) {
}
}
public InputStream getInputStream(final FileHeader hd) throws IOException {
final ByteArrayOutputStream out = new ByteArrayOutputStream();

try {
extractFile(hd, out);
} catch (RarException e) {
throw new IOException("RAR extracting issue", e);
} finally {
try {
out.close();
} catch (IOException e) {
}
}).start();
}

return in;
return new ByteArrayInputStream(out.toByteArray());
}

private void doExtractFile(FileHeader hd, OutputStream os)
Expand Down
56 changes: 28 additions & 28 deletions unrar/src/main/java/com/github/junrar/unpack/Unpack20.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,78 +233,78 @@ protected void makeDecodeTables(byte[] lenTab, int offset, Decode dec,

Arrays.fill(lenCount, 0);// memset(LenCount,0,sizeof(LenCount));

Arrays.fill(dec.getDecodeNum(), 0);// memset(Dec->DecodeNum,0,Size*sizeof(*Dec->DecodeNum));
Arrays.fill(dec.decodeNum, 0);// memset(Dec->DecodeNum,0,Size*sizeof(*Dec->DecodeNum));

for (i = 0; i < size; i++) {
lenCount[(int) (lenTab[offset + i] & 0xF)]++;
}
lenCount[0] = 0;
for (tmpPos[0] = 0, dec.getDecodePos()[0] = 0, dec.getDecodeLen()[0] = 0, N = 0, i = 1; i < 16; i++) {
for (tmpPos[0] = 0, dec.decodePos[0] = 0, dec.decodeLen[0] = 0, N = 0, i = 1; i < 16; i++) {
N = 2 * (N + lenCount[i]);
M = N << (15 - i);
if (M > 0xFFFF) {
M = 0xFFFF;
}
dec.getDecodeLen()[i] = (int) M;
tmpPos[i] = dec.getDecodePos()[i] = dec.getDecodePos()[i - 1]
dec.decodeLen[i] = (int) M;
tmpPos[i] = dec.decodePos[i] = dec.decodePos[i - 1]
+ lenCount[i - 1];
}

for (i = 0; i < size; i++) {
if (lenTab[offset + i] != 0) {
dec.getDecodeNum()[tmpPos[lenTab[offset + i] & 0xF]++] = i;
dec.decodeNum[tmpPos[lenTab[offset + i] & 0xF]++] = i;
}
}
dec.setMaxNum(size);
dec.maxNum = size;
}

protected int decodeNumber(Decode dec)
{
int bits;
long bitField = getbits() & 0xfffe;
// if (bitField < dec.getDecodeLen()[8]) {
// if (bitField < dec.getDecodeLen()[4]) {
// if (bitField < dec.getDecodeLen()[2]) {
// if (bitField < dec.getDecodeLen()[1]) {
// if (bitField < dec.decodeLen[8]) {
// if (bitField < dec.decodeLen[4]) {
// if (bitField < dec.decodeLen[2]) {
// if (bitField < dec.decodeLen[1]) {
// bits = 1;
// } else {
// bits = 2;
// }
// } else {
// if (bitField < dec.getDecodeLen()[3]) {
// if (bitField < dec.decodeLen[3]) {
// bits = 3;
// } else {
// bits = 4;
// }
// }
// } else {
// if (bitField < dec.getDecodeLen()[6]) {
// if (bitField < dec.getDecodeLen()[5])
// if (bitField < dec.decodeLen[6]) {
// if (bitField < dec.decodeLen[5])
// bits = 5;
// else
// bits = 6;
// } else {
// if (bitField < dec.getDecodeLen()[7]) {
// if (bitField < dec.decodeLen[7]) {
// bits = 7;
// } else {
// bits = 8;
// }
// }
// }
// } else {
// if (bitField < dec.getDecodeLen()[12]) {
// if (bitField < dec.getDecodeLen()[10])
// if (bitField < dec.getDecodeLen()[9])
// if (bitField < dec.decodeLen[12]) {
// if (bitField < dec.decodeLen[10])
// if (bitField < dec.decodeLen[9])
// bits = 9;
// else
// bits = 10;
// else if (bitField < dec.getDecodeLen()[11])
// else if (bitField < dec.decodeLen[11])
// bits = 11;
// else
// bits = 12;
// } else {
// if (bitField < dec.getDecodeLen()[14]) {
// if (bitField < dec.getDecodeLen()[13]) {
// if (bitField < dec.decodeLen[14]) {
// if (bitField < dec.decodeLen[13]) {
// bits = 13;
// } else {
// bits = 14;
Expand All @@ -315,13 +315,13 @@ protected int decodeNumber(Decode dec)
// }
// }
// addbits(bits);
// int N = dec.getDecodePos()[bits]
// + (((int) bitField - dec.getDecodeLen()[bits - 1]) >>> (16 - bits));
// if (N >= dec.getMaxNum()) {
// int N = dec.decodePos[bits]
// + (((int) bitField - dec.decodeLen[bits - 1]) >>> (16 - bits));
// if (N >= dec.maxNum) {
// N = 0;
// }
// return (dec.getDecodeNum()[N]);
int[] decodeLen = dec.getDecodeLen();
// return (dec.decodeNum[N]);
int[] decodeLen = dec.decodeLen;
if (bitField < decodeLen[8]) {
if (bitField < decodeLen[4]) {
if (bitField < decodeLen[2]) {
Expand Down Expand Up @@ -375,12 +375,12 @@ else if (bitField < decodeLen[11])
}
}
addbits(bits);
int N = dec.getDecodePos()[bits]
int N = dec.decodePos[bits]
+ (((int) bitField - decodeLen[bits - 1]) >>> (16 - bits));
if (N >= dec.getMaxNum()) {
if (N >= dec.maxNum) {
N = 0;
}
return (dec.getDecodeNum()[N]);
return (dec.decodeNum[N]);
}

protected boolean ReadTables20() throws IOException, RarException
Expand Down
54 changes: 4 additions & 50 deletions unrar/src/main/java/com/github/junrar/unpack/decode/Decode.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,57 +25,11 @@
*/
public class Decode
{
private int maxNum;
public int maxNum;

private final int[] decodeLen = new int[16];
public final int[] decodeLen = new int[16];

private final int[] decodePos = new int[16];

protected int[] decodeNum = new int[2];

/**
* returns the decode Length array
* @return decodeLength
*/
public int[] getDecodeLen()
{
return decodeLen;
}

/**
* returns the decode num array
* @return decodeNum
*/
public int[] getDecodeNum()
{
return decodeNum;
}

/**
* returns the decodePos array
* @return decodePos
*/
public int[] getDecodePos()
{
return decodePos;
}

/**
* returns the max num
* @return maxNum
*/
public int getMaxNum()
{
return maxNum;
}

/**
* sets the max num
* @param maxNum to be set to maxNum
*/
public void setMaxNum(int maxNum)
{
this.maxNum = maxNum;
}
public final int[] decodePos = new int[16];

public int[] decodeNum = new int[2];
}