mirror of
https://github.com/zxing/zxing.git
synced 2024-11-12 14:04:06 -08:00
BitArray perf improvement, possibly addressing https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=45189
This commit is contained in:
parent
9460f0620a
commit
4bd257e8c5
|
@ -25,12 +25,15 @@ import java.util.Arrays;
|
||||||
*/
|
*/
|
||||||
public final class BitArray implements Cloneable {
|
public final class BitArray implements Cloneable {
|
||||||
|
|
||||||
|
private static final int[] EMPTY_BITS = {};
|
||||||
|
private static final float LOAD_FACTOR = 0.75f;
|
||||||
|
|
||||||
private int[] bits;
|
private int[] bits;
|
||||||
private int size;
|
private int size;
|
||||||
|
|
||||||
public BitArray() {
|
public BitArray() {
|
||||||
this.size = 0;
|
this.size = 0;
|
||||||
this.bits = new int[1];
|
this.bits = EMPTY_BITS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BitArray(int size) {
|
public BitArray(int size) {
|
||||||
|
@ -52,9 +55,9 @@ public final class BitArray implements Cloneable {
|
||||||
return (size + 7) / 8;
|
return (size + 7) / 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ensureCapacity(int size) {
|
private void ensureCapacity(int newSize) {
|
||||||
if (size > bits.length * 32) {
|
if (newSize > bits.length * 32) {
|
||||||
int[] newBits = makeArray(size);
|
int[] newBits = makeArray((int) Math.ceil(newSize / LOAD_FACTOR));
|
||||||
System.arraycopy(bits, 0, newBits, 0, bits.length);
|
System.arraycopy(bits, 0, newBits, 0, bits.length);
|
||||||
this.bits = newBits;
|
this.bits = newBits;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue