diff options
author | Lei Zhang <thestig@chromium.org> | 2018-10-01 17:33:49 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-10-01 17:33:49 +0000 |
commit | 673af68584b6ada36682c33acddfea2bcd749030 (patch) | |
tree | 3b75d42726768d9f7476802eb5415d7cb809281f /fxbarcode/common/reedsolomon | |
parent | 48ce3d08faa51bf00edaa3ae0afda9bf86e14a39 (diff) | |
download | pdfium-673af68584b6ada36682c33acddfea2bcd749030.tar.xz |
Remove some "exceptions" from reedsolomon code.
Change-Id: If8c45af624ed6df7b6d7416bb4e195f4097b0574
Reviewed-on: https://pdfium-review.googlesource.com/43191
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Diffstat (limited to 'fxbarcode/common/reedsolomon')
-rw-r--r-- | fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.cpp | 38 | ||||
-rw-r--r-- | fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h | 7 | ||||
-rw-r--r-- | fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp | 14 |
3 files changed, 21 insertions, 38 deletions
diff --git a/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.cpp b/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.cpp index 3f761054c4..a5657e1747 100644 --- a/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.cpp +++ b/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.cpp @@ -76,28 +76,22 @@ CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256::GetOne() const { std::unique_ptr<CBC_ReedSolomonGF256Poly> CBC_ReedSolomonGF256::BuildMonomial( int32_t degree, - int32_t coefficient, - int32_t& e) { - if (degree < 0) { - e = BCExceptionDegreeIsNegative; + int32_t coefficient) { + if (degree < 0) return nullptr; - } - if (coefficient == 0) { - auto temp = m_zero->Clone(); - if (!temp) - e = BCExceptionGeneric; - return temp; - } + + if (coefficient == 0) + return m_zero->Clone(); + std::vector<int32_t> coefficients(degree + 1); coefficients[0] = coefficient; auto temp = pdfium::MakeUnique<CBC_ReedSolomonGF256Poly>(); - if (!temp->Init(this, &coefficients)) { - e = BCExceptionGeneric; + if (!temp->Init(this, &coefficients)) return nullptr; - } return temp; } +// static int32_t CBC_ReedSolomonGF256::AddOrSubtract(int32_t a, int32_t b) { return a ^ b; } @@ -106,19 +100,9 @@ int32_t CBC_ReedSolomonGF256::Exp(int32_t a) { return m_expTable[a]; } -int32_t CBC_ReedSolomonGF256::Log(int32_t a, int32_t& e) { - if (a == 0) { - e = BCExceptionAIsZero; - return 0; - } - return m_logTable[a]; -} - -int32_t CBC_ReedSolomonGF256::Inverse(int32_t a, int32_t& e) { - if (a == 0) { - e = BCExceptionAIsZero; - return 0; - } +Optional<int32_t> CBC_ReedSolomonGF256::Inverse(int32_t a) { + if (a == 0) + return {}; return m_expTable[255 - m_logTable[a]]; } diff --git a/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h b/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h index 9f0fcd316f..199e479710 100644 --- a/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h +++ b/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h @@ -10,6 +10,7 @@ #include <memory> #include "fxbarcode/utils.h" +#include "third_party/base/optional.h" class CBC_ReedSolomonGF256Poly; @@ -24,12 +25,10 @@ class CBC_ReedSolomonGF256 { CBC_ReedSolomonGF256Poly* GetZero() const; CBC_ReedSolomonGF256Poly* GetOne() const; std::unique_ptr<CBC_ReedSolomonGF256Poly> BuildMonomial(int32_t degree, - int32_t coefficient, - int32_t& e); + int32_t coefficient); static int32_t AddOrSubtract(int32_t a, int32_t b); int32_t Exp(int32_t a); - int32_t Log(int32_t a, int32_t& e); - int32_t Inverse(int32_t a, int32_t& e); + Optional<int32_t> Inverse(int32_t a); int32_t Multiply(int32_t a, int32_t b); void Init(); diff --git a/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp b/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp index ef83691d4f..0c56c6e60b 100644 --- a/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp +++ b/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp @@ -210,22 +210,22 @@ std::unique_ptr<CBC_ReedSolomonGF256Poly> CBC_ReedSolomonGF256Poly::Divide( if (!remainder) return nullptr; - int e = BCExceptionNO; int32_t denominatorLeadingTerm = other->GetCoefficients(other->GetDegree()); - int32_t inverseDenominatorLeadingTeam = - m_field->Inverse(denominatorLeadingTerm, e); - if (e != BCExceptionNO) + Optional<int32_t> inverseDenominatorLeadingTeam = + m_field->Inverse(denominatorLeadingTerm); + if (!inverseDenominatorLeadingTeam.has_value()) return nullptr; + while (remainder->GetDegree() >= other->GetDegree() && !remainder->IsZero()) { int32_t degreeDifference = remainder->GetDegree() - other->GetDegree(); int32_t scale = m_field->Multiply(remainder->GetCoefficients((remainder->GetDegree())), - inverseDenominatorLeadingTeam); + inverseDenominatorLeadingTeam.value()); auto term = other->MultiplyByMonomial(degreeDifference, scale); if (!term) return nullptr; - auto iteratorQuotient = m_field->BuildMonomial(degreeDifference, scale, e); - if (e != BCExceptionNO) + auto iteratorQuotient = m_field->BuildMonomial(degreeDifference, scale); + if (!iteratorQuotient) return nullptr; quotient = quotient->AddOrSubtract(iteratorQuotient.get()); if (!quotient) |