Tidy static/global usage in BC_ReedSolomonGF256.cpp - Move some trivial getters to .h file. - Remove one unused constant. - Move the other constant into the only file that uses it. - Prefix with g_ so that it is clear that the eventual |delete| is operating on a global and can't be a smart pointer instead. Change-Id: Ice83dea14c84a5c72ccbc8d0f7e97a2e1b5719a0 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/54591 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/fxbarcode/BC_Library.cpp b/fxbarcode/BC_Library.cpp index 80de23c..393f329 100644 --- a/fxbarcode/BC_Library.cpp +++ b/fxbarcode/BC_Library.cpp
@@ -8,8 +8,8 @@ #include <stdint.h> -#include "fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h" #include "fxbarcode/datamatrix/BC_SymbolInfo.h" +#include "fxbarcode/qrcode/BC_QRCoderEncoder.h" #include "fxbarcode/qrcode/BC_QRCoderErrorCorrectionLevel.h" #include "fxbarcode/qrcode/BC_QRCoderMode.h" #include "fxbarcode/qrcode/BC_QRCoderVersion.h" @@ -18,7 +18,7 @@ CBC_QRCoderErrorCorrectionLevel::Initialize(); CBC_QRCoderMode::Initialize(); CBC_QRCoderVersion::Initialize(); - CBC_ReedSolomonGF256::Initialize(); + CBC_QRCoderEncoder::Initialize(); CBC_SymbolInfo::Initialize(); } @@ -26,6 +26,6 @@ CBC_QRCoderErrorCorrectionLevel::Finalize(); CBC_QRCoderMode::Finalize(); CBC_QRCoderVersion::Finalize(); - CBC_ReedSolomonGF256::Finalize(); + CBC_QRCoderEncoder::Finalize(); CBC_SymbolInfo::Finalize(); }
diff --git a/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.cpp b/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.cpp index b0dd0a2..f2d86b3 100644 --- a/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.cpp +++ b/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.cpp
@@ -27,23 +27,6 @@ #include "fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h" #include "third_party/base/ptr_util.h" -CBC_ReedSolomonGF256* CBC_ReedSolomonGF256::QRCodeField = nullptr; -CBC_ReedSolomonGF256* CBC_ReedSolomonGF256::DataMatrixField = nullptr; - -void CBC_ReedSolomonGF256::Initialize() { - QRCodeField = new CBC_ReedSolomonGF256(0x011D); - QRCodeField->Init(); - DataMatrixField = new CBC_ReedSolomonGF256(0x012D); - DataMatrixField->Init(); -} - -void CBC_ReedSolomonGF256::Finalize() { - delete QRCodeField; - QRCodeField = nullptr; - delete DataMatrixField; - DataMatrixField = nullptr; -} - CBC_ReedSolomonGF256::CBC_ReedSolomonGF256(int32_t primitive) { int32_t x = 1; for (int32_t j = 0; j < 256; j++) { @@ -68,14 +51,6 @@ CBC_ReedSolomonGF256::~CBC_ReedSolomonGF256() {} -CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256::GetZero() const { - return m_zero.get(); -} - -CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256::GetOne() const { - return m_one.get(); -} - std::unique_ptr<CBC_ReedSolomonGF256Poly> CBC_ReedSolomonGF256::BuildMonomial( int32_t degree, int32_t coefficient) {
diff --git a/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h b/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h index a9cf7ef..30f5524 100644 --- a/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h +++ b/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h
@@ -18,11 +18,9 @@ explicit CBC_ReedSolomonGF256(int32_t primitive); ~CBC_ReedSolomonGF256(); - static void Initialize(); - static void Finalize(); + CBC_ReedSolomonGF256Poly* GetZero() const { return m_zero.get(); } + CBC_ReedSolomonGF256Poly* GetOne() const { return m_one.get(); } - CBC_ReedSolomonGF256Poly* GetZero() const; - CBC_ReedSolomonGF256Poly* GetOne() const; std::unique_ptr<CBC_ReedSolomonGF256Poly> BuildMonomial(int32_t degree, int32_t coefficient); static int32_t AddOrSubtract(int32_t a, int32_t b); @@ -31,9 +29,6 @@ int32_t Multiply(int32_t a, int32_t b); void Init(); - static CBC_ReedSolomonGF256* QRCodeField; - static CBC_ReedSolomonGF256* DataMatrixField; - private: std::unique_ptr<CBC_ReedSolomonGF256Poly> m_zero; std::unique_ptr<CBC_ReedSolomonGF256Poly> m_one;
diff --git a/fxbarcode/qrcode/BC_QRCoderEncoder.cpp b/fxbarcode/qrcode/BC_QRCoderEncoder.cpp index 02f42bf..2ecd3b8 100644 --- a/fxbarcode/qrcode/BC_QRCoderEncoder.cpp +++ b/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
@@ -44,6 +44,8 @@ namespace { +CBC_ReedSolomonGF256* g_QRCodeField = nullptr; + struct QRCoderBlockPair { std::vector<uint8_t> data; std::vector<uint8_t> ecc; @@ -230,7 +232,7 @@ std::copy(dataBytes.begin(), dataBytes.end(), toEncode.begin()); std::vector<uint8_t> ecBytes; - CBC_ReedSolomonEncoder encoder(CBC_ReedSolomonGF256::QRCodeField); + CBC_ReedSolomonEncoder encoder(g_QRCodeField); if (encoder.Encode(&toEncode, numEcBytesInBlock)) { ecBytes = std::vector<uint8_t>(toEncode.begin() + dataBytes.size(), toEncode.end()); @@ -400,6 +402,18 @@ } // namespace // static +void CBC_QRCoderEncoder::Initialize() { + g_QRCodeField = new CBC_ReedSolomonGF256(0x011D); + g_QRCodeField->Init(); +} + +// static +void CBC_QRCoderEncoder::Finalize() { + delete g_QRCodeField; + g_QRCodeField = nullptr; +} + +// static bool CBC_QRCoderEncoder::Encode(WideStringView content, const CBC_QRCoderErrorCorrectionLevel* ecLevel, CBC_QRCoder* qrCode) {
diff --git a/fxbarcode/qrcode/BC_QRCoderEncoder.h b/fxbarcode/qrcode/BC_QRCoderEncoder.h index 75fd2e5..a3af1fc 100644 --- a/fxbarcode/qrcode/BC_QRCoderEncoder.h +++ b/fxbarcode/qrcode/BC_QRCoderEncoder.h
@@ -17,6 +17,8 @@ CBC_QRCoderEncoder() = delete; ~CBC_QRCoderEncoder() = delete; + static void Initialize(); + static void Finalize(); static bool Encode(WideStringView content, const CBC_QRCoderErrorCorrectionLevel* ecLevel, CBC_QRCoder* qrCode);