summaryrefslogtreecommitdiff
path: root/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonDecoder.cpp
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-04-29 11:24:14 -0700
committerCommit bot <commit-bot@chromium.org>2016-04-29 11:24:15 -0700
commitd5d07dcf59ddc6439f73382c6e0b9e6d1851000d (patch)
tree3430639a1c286570a60e946e1b850aeeedaaa05a /xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonDecoder.cpp
parentcd1e9ff4f432cbc29ed279e6891fb7ddc2ea3734 (diff)
downloadpdfium-d5d07dcf59ddc6439f73382c6e0b9e6d1851000d.tar.xz
Replace CFX_PtrArray with typesafe CFX_ArrayTemplate, part 8
This also removes another hand-written bubblesort in favor of the std::sort() STL function. Review-Url: https://codereview.chromium.org/1937513002
Diffstat (limited to 'xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonDecoder.cpp')
-rw-r--r--xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonDecoder.cpp66
1 files changed, 33 insertions, 33 deletions
diff --git a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonDecoder.cpp b/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonDecoder.cpp
index ff91c9ddc3..81abd56370 100644
--- a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonDecoder.cpp
+++ b/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonDecoder.cpp
@@ -58,13 +58,11 @@ void CBC_ReedSolomonDecoder::Decode(CFX_Int32Array* received,
std::unique_ptr<CBC_ReedSolomonGF256Poly> temp(
m_field->BuildMonomial(twoS, 1, e));
BC_EXCEPTION_CHECK_ReturnVoid(e);
- std::unique_ptr<CFX_PtrArray> sigmaOmega(
+ std::unique_ptr<CFX_ArrayTemplate<CBC_ReedSolomonGF256Poly*>> sigmaOmega(
RunEuclideanAlgorithm(temp.get(), &syndrome, twoS, e));
BC_EXCEPTION_CHECK_ReturnVoid(e);
- std::unique_ptr<CBC_ReedSolomonGF256Poly> sigma(
- (CBC_ReedSolomonGF256Poly*)(*sigmaOmega)[0]);
- std::unique_ptr<CBC_ReedSolomonGF256Poly> omega(
- (CBC_ReedSolomonGF256Poly*)(*sigmaOmega)[1]);
+ std::unique_ptr<CBC_ReedSolomonGF256Poly> sigma((*sigmaOmega)[0]);
+ std::unique_ptr<CBC_ReedSolomonGF256Poly> omega((*sigmaOmega)[1]);
std::unique_ptr<CFX_Int32Array> errorLocations(
FindErrorLocations(sigma.get(), e));
BC_EXCEPTION_CHECK_ReturnVoid(e);
@@ -83,28 +81,29 @@ void CBC_ReedSolomonDecoder::Decode(CFX_Int32Array* received,
(*received)[position], (*errorMagnitudes)[k]);
}
}
-CFX_PtrArray* CBC_ReedSolomonDecoder::RunEuclideanAlgorithm(
- CBC_ReedSolomonGF256Poly* a,
- CBC_ReedSolomonGF256Poly* b,
- int32_t R,
- int32_t& e) {
+
+CFX_ArrayTemplate<CBC_ReedSolomonGF256Poly*>*
+CBC_ReedSolomonDecoder::RunEuclideanAlgorithm(CBC_ReedSolomonGF256Poly* a,
+ CBC_ReedSolomonGF256Poly* b,
+ int32_t R,
+ int32_t& e) {
if (a->GetDegree() < b->GetDegree()) {
CBC_ReedSolomonGF256Poly* temp = a;
a = b;
b = temp;
}
std::unique_ptr<CBC_ReedSolomonGF256Poly> rLast(a->Clone(e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
std::unique_ptr<CBC_ReedSolomonGF256Poly> r(b->Clone(e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
std::unique_ptr<CBC_ReedSolomonGF256Poly> sLast(m_field->GetOne()->Clone(e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
std::unique_ptr<CBC_ReedSolomonGF256Poly> s(m_field->GetZero()->Clone(e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
std::unique_ptr<CBC_ReedSolomonGF256Poly> tLast(m_field->GetZero()->Clone(e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
std::unique_ptr<CBC_ReedSolomonGF256Poly> t(m_field->GetOne()->Clone(e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
while (r->GetDegree() >= R / 2) {
std::unique_ptr<CBC_ReedSolomonGF256Poly> rLastLast = std::move(rLast);
std::unique_ptr<CBC_ReedSolomonGF256Poly> sLastLast = std::move(sLast);
@@ -114,53 +113,54 @@ CFX_PtrArray* CBC_ReedSolomonDecoder::RunEuclideanAlgorithm(
tLast = std::move(t);
if (rLast->IsZero()) {
e = BCExceptionR_I_1IsZero;
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
}
r.reset(rLastLast->Clone(e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
std::unique_ptr<CBC_ReedSolomonGF256Poly> q(m_field->GetZero()->Clone(e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
int32_t denominatorLeadingTerm = rLast->GetCoefficients(rLast->GetDegree());
int32_t dltInverse = m_field->Inverse(denominatorLeadingTerm, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
while (r->GetDegree() >= rLast->GetDegree() && !(r->IsZero())) {
int32_t degreeDiff = r->GetDegree() - rLast->GetDegree();
int32_t scale =
m_field->Multiply(r->GetCoefficients(r->GetDegree()), dltInverse);
std::unique_ptr<CBC_ReedSolomonGF256Poly> build(
m_field->BuildMonomial(degreeDiff, scale, e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
q.reset(q->AddOrSubtract(build.get(), e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
std::unique_ptr<CBC_ReedSolomonGF256Poly> multiply(
rLast->MultiplyByMonomial(degreeDiff, scale, e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
r.reset(r->AddOrSubtract(multiply.get(), e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
}
std::unique_ptr<CBC_ReedSolomonGF256Poly> temp1(
q->Multiply(sLast.get(), e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
s.reset(temp1->AddOrSubtract(sLastLast.get(), e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
std::unique_ptr<CBC_ReedSolomonGF256Poly> temp5(
q->Multiply(tLast.get(), e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
t.reset(temp5->AddOrSubtract(tLastlast.get(), e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
}
int32_t sigmaTildeAtZero = t->GetCoefficients(0);
if (sigmaTildeAtZero == 0) {
e = BCExceptionIsZero;
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
}
int32_t inverse = m_field->Inverse(sigmaTildeAtZero, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
std::unique_ptr<CBC_ReedSolomonGF256Poly> sigma(t->Multiply(inverse, e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
std::unique_ptr<CBC_ReedSolomonGF256Poly> omega(r->Multiply(inverse, e));
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- CFX_PtrArray* temp = new CFX_PtrArray;
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
+ CFX_ArrayTemplate<CBC_ReedSolomonGF256Poly*>* temp =
+ new CFX_ArrayTemplate<CBC_ReedSolomonGF256Poly*>();
temp->Add(sigma.release());
temp->Add(omega.release());
return temp;