mirror of
https://github.com/revanced/smali.git
synced 2025-05-27 19:30:13 +02:00
MemoryDataStore: More efficient overridable growth policy
This commit is contained in:
parent
b0a69fce34
commit
c645b9d546
@ -7,8 +7,8 @@ import java.io.OutputStream;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class MemoryDataStore implements DexDataStore {
|
||||
protected byte[] buf;
|
||||
protected int size = 0;
|
||||
private byte[] buf;
|
||||
private int size = 0;
|
||||
|
||||
public MemoryDataStore() {
|
||||
this(1024 * 1024);
|
||||
@ -52,15 +52,21 @@ public class MemoryDataStore implements DexDataStore {
|
||||
};
|
||||
}
|
||||
|
||||
protected void growBufferIfNeeded(int minSize) {
|
||||
private void growBufferIfNeeded(int minSize) {
|
||||
if (minSize > size) {
|
||||
if (minSize > buf.length) {
|
||||
buf = Arrays.copyOf(buf, (int)(minSize * 1.2));
|
||||
int newSize = getNewBufferSize(buf.length, minSize);
|
||||
if (newSize < minSize) throw new IndexOutOfBoundsException();
|
||||
buf = Arrays.copyOf(buf, newSize);
|
||||
}
|
||||
size = minSize;
|
||||
}
|
||||
}
|
||||
|
||||
protected int getNewBufferSize(int currentSize, int newMinSize) {
|
||||
return (int)(newMinSize * 1.2);
|
||||
}
|
||||
|
||||
@Nonnull @Override public InputStream readAt(final int offset) {
|
||||
return new InputStream() {
|
||||
private int position = offset;
|
||||
|
Loading…
x
Reference in New Issue
Block a user