diff options
author | Tom Sepez <tsepez@chromium.org> | 2017-03-28 12:06:45 -0700 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-03-28 19:22:50 +0000 |
commit | 8b6186f89002099d406508acecf4bccc4ef64c95 (patch) | |
tree | df104ee415cfa90a53a23b88f1f66c3c2fd8d84e /xfa/fxbarcode/common/reedsolomon | |
parent | b0baff546bdcd911c80007829d9af5f05d0c04b0 (diff) | |
download | pdfium-8b6186f89002099d406508acecf4bccc4ef64c95.tar.xz |
Remove CFX_ArrayTemplate from FX barcode code.
This is now the last usage in pdfium, types to be removed
in a follow-on CL.
Change-Id: I16f67eb3eb99f21bb231829168203be125129ad7
Reviewed-on: https://pdfium-review.googlesource.com/3247
Reviewed-by: dsinclair <dsinclair@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fxbarcode/common/reedsolomon')
5 files changed, 102 insertions, 108 deletions
diff --git a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomon.cpp b/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomon.cpp index 7698890366..82a729b067 100644 --- a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomon.cpp +++ b/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomon.cpp @@ -30,18 +30,17 @@ CBC_ReedSolomonEncoder::CBC_ReedSolomonEncoder(CBC_ReedSolomonGF256* field) { m_field = field; } + void CBC_ReedSolomonEncoder::Init() { - m_cachedGenerators.Add(new CBC_ReedSolomonGF256Poly(m_field, 1)); + m_cachedGenerators.push_back(new CBC_ReedSolomonGF256Poly(m_field, 1)); } -CBC_ReedSolomonGF256Poly* CBC_ReedSolomonEncoder::BuildGenerator(int32_t degree, + +CBC_ReedSolomonGF256Poly* CBC_ReedSolomonEncoder::BuildGenerator(size_t degree, int32_t& e) { - if (degree >= m_cachedGenerators.GetSize()) { - CBC_ReedSolomonGF256Poly* lastGenerator = - m_cachedGenerators[m_cachedGenerators.GetSize() - 1]; - for (int32_t d = m_cachedGenerators.GetSize(); d <= degree; d++) { - CFX_ArrayTemplate<int32_t> temp; - temp.Add(1); - temp.Add(m_field->Exp(d - 1)); + if (degree >= m_cachedGenerators.size()) { + CBC_ReedSolomonGF256Poly* lastGenerator = m_cachedGenerators.back(); + for (size_t d = m_cachedGenerators.size(); d <= degree; ++d) { + std::vector<int32_t> temp = {1, m_field->Exp(d - 1)}; CBC_ReedSolomonGF256Poly temp_poly; temp_poly.Init(m_field, &temp, e); if (e != BCExceptionNO) @@ -50,31 +49,31 @@ CBC_ReedSolomonGF256Poly* CBC_ReedSolomonEncoder::BuildGenerator(int32_t degree, lastGenerator->Multiply(&temp_poly, e); if (e != BCExceptionNO) return nullptr; - m_cachedGenerators.Add(nextGenerator); + m_cachedGenerators.push_back(nextGenerator); lastGenerator = nextGenerator; } } return m_cachedGenerators[degree]; } -void CBC_ReedSolomonEncoder::Encode(CFX_ArrayTemplate<int32_t>* toEncode, - int32_t ecBytes, + +void CBC_ReedSolomonEncoder::Encode(std::vector<int32_t>* toEncode, + size_t ecBytes, int32_t& e) { if (ecBytes == 0) { e = BCExceptionNoCorrectionBytes; return; } - int32_t dataBytes = toEncode->GetSize() - ecBytes; - if (dataBytes <= 0) { + if (toEncode->size() <= ecBytes) { e = BCExceptionNoDataBytesProvided; return; } CBC_ReedSolomonGF256Poly* generator = BuildGenerator(ecBytes, e); if (e != BCExceptionNO) return; - CFX_ArrayTemplate<int32_t> infoCoefficients; - infoCoefficients.SetSize(dataBytes); - for (int32_t x = 0; x < dataBytes; x++) { - infoCoefficients[x] = toEncode->operator[](x); + size_t dataBytes = toEncode->size() - ecBytes; + std::vector<int32_t> infoCoefficients(dataBytes); + for (size_t x = 0; x < dataBytes; x++) { + infoCoefficients[x] = (*toEncode)[x]; } CBC_ReedSolomonGF256Poly info; info.Init(m_field, &infoCoefficients, e); @@ -84,25 +83,23 @@ void CBC_ReedSolomonEncoder::Encode(CFX_ArrayTemplate<int32_t>* toEncode, info.MultiplyByMonomial(ecBytes, 1, e)); if (e != BCExceptionNO) return; - std::unique_ptr<CFX_ArrayTemplate<CBC_ReedSolomonGF256Poly*>> temp( + std::unique_ptr<std::vector<CBC_ReedSolomonGF256Poly*>> temp( infoTemp->Divide(generator, e)); if (e != BCExceptionNO) return; CBC_ReedSolomonGF256Poly* remainder = (*temp)[1]; - CFX_ArrayTemplate<int32_t>* coefficients = remainder->GetCoefficients(); - int32_t numZeroCoefficients = ecBytes - coefficients->GetSize(); - for (int32_t i = 0; i < numZeroCoefficients; i++) { + std::vector<int32_t>* coefficients = remainder->GetCoefficients(); + size_t numZeroCoefficients = + ecBytes > coefficients->size() ? ecBytes - coefficients->size() : 0; + for (size_t i = 0; i < numZeroCoefficients; i++) (*toEncode)[dataBytes + i] = 0; - } - for (int32_t y = 0; y < coefficients->GetSize(); y++) { - (*toEncode)[dataBytes + numZeroCoefficients + y] = - coefficients->operator[](y); - } - for (int32_t k = 0; k < temp->GetSize(); k++) { + for (size_t y = 0; y < coefficients->size(); y++) + (*toEncode)[dataBytes + numZeroCoefficients + y] = (*coefficients)[y]; + for (size_t k = 0; k < temp->size(); k++) delete (*temp)[k]; - } } + CBC_ReedSolomonEncoder::~CBC_ReedSolomonEncoder() { - for (int32_t i = 0; i < m_cachedGenerators.GetSize(); i++) + for (size_t i = 0; i < m_cachedGenerators.size(); i++) delete m_cachedGenerators[i]; } diff --git a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomon.h b/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomon.h index 95828f1a0e..5e5c7c52d3 100644 --- a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomon.h +++ b/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomon.h @@ -7,6 +7,8 @@ #ifndef XFA_FXBARCODE_COMMON_REEDSOLOMON_BC_REEDSOLOMON_H_ #define XFA_FXBARCODE_COMMON_REEDSOLOMON_BC_REEDSOLOMON_H_ +#include <vector> + #include "core/fxcrt/fx_basic.h" class CBC_ReedSolomonGF256; @@ -17,16 +19,14 @@ class CBC_ReedSolomonEncoder { explicit CBC_ReedSolomonEncoder(CBC_ReedSolomonGF256* field); virtual ~CBC_ReedSolomonEncoder(); - void Encode(CFX_ArrayTemplate<int32_t>* toEncode, - int32_t ecBytes, - int32_t& e); + void Encode(std::vector<int32_t>* toEncode, size_t ecBytes, int32_t& e); virtual void Init(); private: - CBC_ReedSolomonGF256Poly* BuildGenerator(int32_t degree, int32_t& e); + CBC_ReedSolomonGF256Poly* BuildGenerator(size_t degree, int32_t& e); CBC_ReedSolomonGF256* m_field; - CFX_ArrayTemplate<CBC_ReedSolomonGF256Poly*> m_cachedGenerators; + std::vector<CBC_ReedSolomonGF256Poly*> m_cachedGenerators; }; #endif // XFA_FXBARCODE_COMMON_REEDSOLOMON_BC_REEDSOLOMON_H_ diff --git a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.cpp b/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.cpp index ce84d8e08d..349ed0789a 100644 --- a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.cpp +++ b/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.cpp @@ -22,6 +22,8 @@ #include "xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h" +#include <vector> + #include "third_party/base/ptr_util.h" #include "xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h" @@ -86,8 +88,7 @@ CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256::BuildMonomial( return nullptr; return temp; } - CFX_ArrayTemplate<int32_t> coefficients; - coefficients.SetSize(degree + 1); + std::vector<int32_t> coefficients(degree + 1); coefficients[0] = coefficient; CBC_ReedSolomonGF256Poly* temp = new CBC_ReedSolomonGF256Poly(); temp->Init(this, &coefficients, e); diff --git a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp b/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp index a0bbc025c4..e4ee30b586 100644 --- a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp +++ b/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp @@ -23,7 +23,9 @@ #include "xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h" #include <memory> +#include <utility> +#include "third_party/base/stl_util.h" #include "xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h" CBC_ReedSolomonGF256Poly::CBC_ReedSolomonGF256Poly(CBC_ReedSolomonGF256* field, @@ -32,69 +34,75 @@ CBC_ReedSolomonGF256Poly::CBC_ReedSolomonGF256Poly(CBC_ReedSolomonGF256* field, return; m_field = field; - m_coefficients.Add(coefficients); + m_coefficients.push_back(coefficients); } + CBC_ReedSolomonGF256Poly::CBC_ReedSolomonGF256Poly() { m_field = nullptr; } + void CBC_ReedSolomonGF256Poly::Init(CBC_ReedSolomonGF256* field, - CFX_ArrayTemplate<int32_t>* coefficients, + std::vector<int32_t>* coefficients, int32_t& e) { - if (!coefficients || coefficients->GetSize() == 0) { + if (!coefficients || coefficients->empty()) { e = BCExceptionCoefficientsSizeIsNull; return; } m_field = field; - int32_t coefficientsLength = coefficients->GetSize(); - if ((coefficientsLength > 1 && (*coefficients)[0] == 0)) { - int32_t firstNonZero = 1; - while ((firstNonZero < coefficientsLength) && - ((*coefficients)[firstNonZero] == 0)) { + size_t coefficientsLength = coefficients->size(); + if (coefficientsLength > 1 && coefficients->front() == 0) { + size_t firstNonZero = 1; + while (firstNonZero < coefficientsLength && + (*coefficients)[firstNonZero] == 0) { firstNonZero++; } if (firstNonZero == coefficientsLength) { - m_coefficients.Copy(*(m_field->GetZero()->GetCoefficients())); + m_coefficients = *(m_field->GetZero()->GetCoefficients()); } else { - m_coefficients.SetSize(coefficientsLength - firstNonZero); - for (int32_t i = firstNonZero, j = 0; i < coefficientsLength; i++, j++) { - m_coefficients[j] = coefficients->operator[](i); - } + m_coefficients.resize(coefficientsLength - firstNonZero); + for (size_t i = firstNonZero, j = 0; i < coefficientsLength; i++, j++) + m_coefficients[j] = (*coefficients)[i]; } } else { - m_coefficients.Copy(*coefficients); + m_coefficients = *coefficients; } } -CFX_ArrayTemplate<int32_t>* CBC_ReedSolomonGF256Poly::GetCoefficients() { + +std::vector<int32_t>* CBC_ReedSolomonGF256Poly::GetCoefficients() { return &m_coefficients; } + int32_t CBC_ReedSolomonGF256Poly::GetDegree() { - return m_coefficients.GetSize() - 1; + return pdfium::CollectionSize<int32_t>(m_coefficients) - 1; } + bool CBC_ReedSolomonGF256Poly::IsZero() { - return m_coefficients[0] == 0; + return m_coefficients.front() == 0; } + int32_t CBC_ReedSolomonGF256Poly::GetCoefficients(int32_t degree) { - return m_coefficients[m_coefficients.GetSize() - 1 - degree]; + return m_coefficients[m_coefficients.size() - 1 - degree]; } + int32_t CBC_ReedSolomonGF256Poly::EvaluateAt(int32_t a) { if (a == 0) { return GetCoefficients(0); } - int32_t size = m_coefficients.GetSize(); + size_t size = m_coefficients.size(); if (a == 1) { int32_t result = 0; - for (int32_t i = 0; i < size; i++) { + for (size_t i = 0; i < size; i++) result = CBC_ReedSolomonGF256::AddOrSubtract(result, m_coefficients[i]); - } return result; } int32_t result = m_coefficients[0]; - for (int32_t j = 1; j < size; j++) { + for (size_t j = 1; j < size; j++) { result = CBC_ReedSolomonGF256::AddOrSubtract(m_field->Multiply(a, result), m_coefficients[j]); } return result; } + CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::Clone(int32_t& e) { CBC_ReedSolomonGF256Poly* temp = new CBC_ReedSolomonGF256Poly(); temp->Init(m_field, &m_coefficients, e); @@ -110,26 +118,19 @@ CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::AddOrSubtract( if (other->IsZero()) return Clone(e); - CFX_ArrayTemplate<int32_t> smallerCoefficients; - smallerCoefficients.Copy(m_coefficients); - CFX_ArrayTemplate<int32_t> largerCoefficients; - largerCoefficients.Copy(*(other->GetCoefficients())); - if (smallerCoefficients.GetSize() > largerCoefficients.GetSize()) { - CFX_ArrayTemplate<int32_t> temp; - temp.Copy(smallerCoefficients); - smallerCoefficients.Copy(largerCoefficients); - largerCoefficients.Copy(temp); + std::vector<int32_t> smallerCoefficients = m_coefficients; + std::vector<int32_t> largerCoefficients = *(other->GetCoefficients()); + if (smallerCoefficients.size() > largerCoefficients.size()) { + std::swap(smallerCoefficients, largerCoefficients); } - CFX_ArrayTemplate<int32_t> sumDiff; - sumDiff.SetSize(largerCoefficients.GetSize()); - int32_t lengthDiff = - largerCoefficients.GetSize() - smallerCoefficients.GetSize(); - for (int32_t i = 0; i < lengthDiff; i++) { + std::vector<int32_t> sumDiff(largerCoefficients.size()); + size_t lengthDiff = largerCoefficients.size() - smallerCoefficients.size(); + for (size_t i = 0; i < lengthDiff; i++) { sumDiff[i] = largerCoefficients[i]; } - for (int32_t j = lengthDiff; j < largerCoefficients.GetSize(); j++) { - sumDiff[j] = (CBC_ReedSolomonGF256::AddOrSubtract( - smallerCoefficients[j - lengthDiff], largerCoefficients[j])); + for (size_t j = lengthDiff; j < largerCoefficients.size(); j++) { + sumDiff[j] = CBC_ReedSolomonGF256::AddOrSubtract( + smallerCoefficients[j - lengthDiff], largerCoefficients[j]); } CBC_ReedSolomonGF256Poly* temp = new CBC_ReedSolomonGF256Poly(); temp->Init(m_field, &sumDiff, e); @@ -143,20 +144,17 @@ CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::Multiply( if (IsZero() || other->IsZero()) return m_field->GetZero()->Clone(e); - CFX_ArrayTemplate<int32_t> aCoefficients; - aCoefficients.Copy(m_coefficients); - int32_t aLength = m_coefficients.GetSize(); - CFX_ArrayTemplate<int32_t> bCoefficients; - bCoefficients.Copy(*(other->GetCoefficients())); - int32_t bLength = other->GetCoefficients()->GetSize(); - CFX_ArrayTemplate<int32_t> product; - product.SetSize(aLength + bLength - 1); - for (int32_t i = 0; i < aLength; i++) { + std::vector<int32_t> aCoefficients = m_coefficients; + std::vector<int32_t> bCoefficients = *(other->GetCoefficients()); + size_t aLength = aCoefficients.size(); + size_t bLength = bCoefficients.size(); + std::vector<int32_t> product(aLength + bLength - 1); + for (size_t i = 0; i < aLength; i++) { int32_t aCoeff = m_coefficients[i]; - for (int32_t j = 0; j < bLength; j++) { + for (size_t j = 0; j < bLength; j++) { product[i + j] = CBC_ReedSolomonGF256::AddOrSubtract( product[i + j], - m_field->Multiply(aCoeff, other->GetCoefficients()->operator[](j))); + m_field->Multiply(aCoeff, (*other->GetCoefficients())[j])); } } CBC_ReedSolomonGF256Poly* temp = new CBC_ReedSolomonGF256Poly(); @@ -172,10 +170,9 @@ CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::Multiply(int32_t scalar, if (scalar == 1) return Clone(e); - int32_t size = m_coefficients.GetSize(); - CFX_ArrayTemplate<int32_t> product; - product.SetSize(size); - for (int32_t i = 0; i < size; i++) { + size_t size = m_coefficients.size(); + std::vector<int32_t> product(size); + for (size_t i = 0; i < size; i++) { product[i] = m_field->Multiply(m_coefficients[i], scalar); } CBC_ReedSolomonGF256Poly* temp = new CBC_ReedSolomonGF256Poly(); @@ -195,11 +192,10 @@ CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::MultiplyByMonomial( if (coefficient == 0) return m_field->GetZero()->Clone(e); - int32_t size = m_coefficients.GetSize(); - CFX_ArrayTemplate<int32_t> product; - product.SetSize(size + degree); - for (int32_t i = 0; i < size; i++) { - product[i] = (m_field->Multiply(m_coefficients[i], coefficient)); + size_t size = m_coefficients.size(); + std::vector<int32_t> product(size + degree); + for (size_t i = 0; i < size; i++) { + product[i] = m_field->Multiply(m_coefficients[i], coefficient); } CBC_ReedSolomonGF256Poly* temp = new CBC_ReedSolomonGF256Poly(); temp->Init(m_field, &product, e); @@ -208,7 +204,7 @@ CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::MultiplyByMonomial( return temp; } -CFX_ArrayTemplate<CBC_ReedSolomonGF256Poly*>* CBC_ReedSolomonGF256Poly::Divide( +std::vector<CBC_ReedSolomonGF256Poly*>* CBC_ReedSolomonGF256Poly::Divide( CBC_ReedSolomonGF256Poly* other, int32_t& e) { if (other->IsZero()) { @@ -247,13 +243,11 @@ CFX_ArrayTemplate<CBC_ReedSolomonGF256Poly*>* CBC_ReedSolomonGF256Poly::Divide( if (e != BCExceptionNO) return nullptr; } - CFX_ArrayTemplate<CBC_ReedSolomonGF256Poly*>* tempPtrA = - new CFX_ArrayTemplate<CBC_ReedSolomonGF256Poly*>(); - tempPtrA->Add(quotient.release()); - tempPtrA->Add(remainder.release()); + std::vector<CBC_ReedSolomonGF256Poly*>* tempPtrA = + new std::vector<CBC_ReedSolomonGF256Poly*>(); + tempPtrA->push_back(quotient.release()); + tempPtrA->push_back(remainder.release()); return tempPtrA; } -CBC_ReedSolomonGF256Poly::~CBC_ReedSolomonGF256Poly() { - m_coefficients.RemoveAll(); -} +CBC_ReedSolomonGF256Poly::~CBC_ReedSolomonGF256Poly() {} diff --git a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h b/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h index ff93264e00..6fc7509399 100644 --- a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h +++ b/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h @@ -7,6 +7,8 @@ #ifndef XFA_FXBARCODE_COMMON_REEDSOLOMON_BC_REEDSOLOMONGF256POLY_H_ #define XFA_FXBARCODE_COMMON_REEDSOLOMON_BC_REEDSOLOMONGF256POLY_H_ +#include <vector> + #include "core/fxcrt/fx_basic.h" class CBC_ReedSolomonGF256; @@ -17,11 +19,11 @@ class CBC_ReedSolomonGF256Poly final { CBC_ReedSolomonGF256Poly(); ~CBC_ReedSolomonGF256Poly(); void Init(CBC_ReedSolomonGF256* field, - CFX_ArrayTemplate<int32_t>* coefficients, + std::vector<int32_t>* coefficients, int32_t& e); int32_t GetCoefficients(int32_t degree); - CFX_ArrayTemplate<int32_t>* GetCoefficients(); + std::vector<int32_t>* GetCoefficients(); int32_t GetDegree(); bool IsZero(); int32_t EvaluateAt(int32_t a); @@ -33,7 +35,7 @@ class CBC_ReedSolomonGF256Poly final { CBC_ReedSolomonGF256Poly* MultiplyByMonomial(int32_t degree, int32_t coefficient, int32_t& e); - CFX_ArrayTemplate<CBC_ReedSolomonGF256Poly*>* Divide( + std::vector<CBC_ReedSolomonGF256Poly*>* Divide( CBC_ReedSolomonGF256Poly* other, int32_t& e); @@ -41,7 +43,7 @@ class CBC_ReedSolomonGF256Poly final { private: CBC_ReedSolomonGF256* m_field; - CFX_ArrayTemplate<int32_t> m_coefficients; + std::vector<int32_t> m_coefficients; }; #endif // XFA_FXBARCODE_COMMON_REEDSOLOMON_BC_REEDSOLOMONGF256POLY_H_ |