minor refactoring to simplify the code on the construction of ArrayRef instances

This commit is contained in:
favoritas37 2016-10-04 21:08:22 +03:00
parent 505f60c264
commit 9941055ae6

View File

@ -47,7 +47,7 @@ GenericGFPoly::GenericGFPoly(Ref<GenericGF> field,
if (firstNonZero == coefficientsLength) {
coefficients_ = field->getZero()->getCoefficients();
} else {
coefficients_ = ArrayRef<int>(new Array<int>(coefficientsLength-firstNonZero));
coefficients_ = ArrayRef<int>(coefficientsLength-firstNonZero);
for (int i = 0; i < (int)coefficients_->size(); i++) {
coefficients_[i] = coefficients[i + firstNonZero];
}
@ -144,7 +144,7 @@ Ref<GenericGFPoly> GenericGFPoly::multiply(Ref<zxing::GenericGFPoly> other) {
ArrayRef<int> bCoefficients = other->getCoefficients();
int bLength = bCoefficients->size();
ArrayRef<int> product(new Array<int>(aLength + bLength - 1));
ArrayRef<int> product(aLength + bLength - 1);
for (int i = 0; i < aLength; i++) {
int aCoeff = aCoefficients[i];
for (int j = 0; j < bLength; j++) {
@ -164,7 +164,7 @@ Ref<GenericGFPoly> GenericGFPoly::multiply(int scalar) {
return Ref<GenericGFPoly>(this);
}
int size = coefficients_->size();
ArrayRef<int> product(new Array<int>(size));
ArrayRef<int> product(size);
for (int i = 0; i < size; i++) {
product[i] = field_->multiply(coefficients_[i], scalar);
}
@ -179,7 +179,7 @@ Ref<GenericGFPoly> GenericGFPoly::multiplyByMonomial(int degree, int coefficient
return field_->getZero();
}
int size = coefficients_->size();
ArrayRef<int> product(new Array<int>(size+degree));
ArrayRef<int> product(size+degree);
for (int i = 0; i < size; i++) {
product[i] = field_->multiply(coefficients_[i], coefficient);
}