mirror of
https://github.com/revanced/smali.git
synced 2025-05-29 04:10: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;
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class MemoryDataStore implements DexDataStore {
|
public class MemoryDataStore implements DexDataStore {
|
||||||
protected byte[] buf;
|
private byte[] buf;
|
||||||
protected int size = 0;
|
private int size = 0;
|
||||||
|
|
||||||
public MemoryDataStore() {
|
public MemoryDataStore() {
|
||||||
this(1024 * 1024);
|
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 > size) {
|
||||||
if (minSize > buf.length) {
|
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;
|
size = minSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected int getNewBufferSize(int currentSize, int newMinSize) {
|
||||||
|
return (int)(newMinSize * 1.2);
|
||||||
|
}
|
||||||
|
|
||||||
@Nonnull @Override public InputStream readAt(final int offset) {
|
@Nonnull @Override public InputStream readAt(final int offset) {
|
||||||
return new InputStream() {
|
return new InputStream() {
|
||||||
private int position = offset;
|
private int position = offset;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user