Move scalar vectors to data partition in fxbarcode/
Change-Id: Ib98046fd939962f281192ebf74d900b0fd5964b9
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/68852
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/fxbarcode/cbc_datamatrix.cpp b/fxbarcode/cbc_datamatrix.cpp
index e8695d2..930f564 100644
--- a/fxbarcode/cbc_datamatrix.cpp
+++ b/fxbarcode/cbc_datamatrix.cpp
@@ -23,6 +23,7 @@
#include <vector>
+#include "core/fxcrt/fx_memory_wrappers.h"
#include "fxbarcode/datamatrix/BC_DataMatrixWriter.h"
#include "third_party/base/ptr_util.h"
@@ -35,7 +36,7 @@
int32_t width;
int32_t height;
auto* pWriter = GetDataMatrixWriter();
- std::vector<uint8_t> data =
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>> data =
pWriter->Encode(WideString(contents), &width, &height);
return pWriter->RenderResult(data, width, height);
}
diff --git a/fxbarcode/cbc_pdf417i.cpp b/fxbarcode/cbc_pdf417i.cpp
index f91f5c6..14883d7 100644
--- a/fxbarcode/cbc_pdf417i.cpp
+++ b/fxbarcode/cbc_pdf417i.cpp
@@ -23,6 +23,7 @@
#include <vector>
+#include "core/fxcrt/fx_memory_wrappers.h"
#include "fxbarcode/pdf417/BC_PDF417Writer.h"
#include "third_party/base/ptr_util.h"
@@ -46,7 +47,8 @@
int32_t width;
int32_t height;
auto* pWriter = GetPDF417Writer();
- std::vector<uint8_t> data = pWriter->Encode(contents, &width, &height);
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>> data =
+ pWriter->Encode(contents, &width, &height);
return pWriter->RenderResult(data, width, height);
}
diff --git a/fxbarcode/cbc_qrcode.cpp b/fxbarcode/cbc_qrcode.cpp
index 5e60fa3..60d3e44 100644
--- a/fxbarcode/cbc_qrcode.cpp
+++ b/fxbarcode/cbc_qrcode.cpp
@@ -23,6 +23,7 @@
#include <vector>
+#include "core/fxcrt/fx_memory_wrappers.h"
#include "fxbarcode/qrcode/BC_QRCodeWriter.h"
#include "third_party/base/ptr_util.h"
@@ -35,7 +36,7 @@
int32_t width;
int32_t height;
CBC_QRCodeWriter* pWriter = GetQRCodeWriter();
- std::vector<uint8_t> data = pWriter->Encode(
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>> data = pWriter->Encode(
contents, pWriter->error_correction_level(), &width, &height);
return pWriter->RenderResult(data, width, height);
}
diff --git a/fxbarcode/common/BC_CommonByteMatrix.cpp b/fxbarcode/common/BC_CommonByteMatrix.cpp
index a05fde0..795593d 100644
--- a/fxbarcode/common/BC_CommonByteMatrix.cpp
+++ b/fxbarcode/common/BC_CommonByteMatrix.cpp
@@ -27,7 +27,8 @@
CBC_CommonByteMatrix::CBC_CommonByteMatrix(int32_t width, int32_t height)
: m_width(width), m_height(height) {
- m_bytes = pdfium::Vector2D<uint8_t>(m_height, m_width);
+ m_bytes =
+ pdfium::Vector2D<uint8_t, FxAllocAllocator<uint8_t>>(m_height, m_width);
clear(0xff);
}
diff --git a/fxbarcode/common/BC_CommonByteMatrix.h b/fxbarcode/common/BC_CommonByteMatrix.h
index c5a66a3..c219aaa 100644
--- a/fxbarcode/common/BC_CommonByteMatrix.h
+++ b/fxbarcode/common/BC_CommonByteMatrix.h
@@ -11,6 +11,7 @@
#include <vector>
+#include "core/fxcrt/fx_memory_wrappers.h"
#include "core/fxcrt/fx_system.h"
#include "third_party/base/span.h"
@@ -31,7 +32,7 @@
private:
int32_t m_width;
int32_t m_height;
- std::vector<uint8_t> m_bytes;
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>> m_bytes;
};
#endif // FXBARCODE_COMMON_BC_COMMONBYTEMATRIX_H_
diff --git a/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp b/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp
index 1d2b39e..16ec3a9 100644
--- a/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp
+++ b/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp
@@ -107,10 +107,11 @@
return true;
}
-std::vector<uint8_t> CBC_DataMatrixWriter::Encode(const WideString& contents,
- int32_t* pOutWidth,
- int32_t* pOutHeight) {
- std::vector<uint8_t> results;
+std::vector<uint8_t, FxAllocAllocator<uint8_t>> CBC_DataMatrixWriter::Encode(
+ const WideString& contents,
+ int32_t* pOutWidth,
+ int32_t* pOutHeight) {
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>> results;
WideString encoded = CBC_HighLevelEncoder::EncodeHighLevel(contents);
if (encoded.IsEmpty())
return results;
@@ -139,7 +140,8 @@
*pOutWidth = bytematrix->GetWidth();
*pOutHeight = bytematrix->GetHeight();
- results = pdfium::Vector2D<uint8_t>(*pOutWidth, *pOutHeight);
+ results = pdfium::Vector2D<uint8_t, FxAllocAllocator<uint8_t>>(*pOutWidth,
+ *pOutHeight);
memcpy(results.data(), bytematrix->GetArray().data(),
*pOutWidth * *pOutHeight);
return results;
diff --git a/fxbarcode/datamatrix/BC_DataMatrixWriter.h b/fxbarcode/datamatrix/BC_DataMatrixWriter.h
index f95612e..473390e 100644
--- a/fxbarcode/datamatrix/BC_DataMatrixWriter.h
+++ b/fxbarcode/datamatrix/BC_DataMatrixWriter.h
@@ -9,6 +9,7 @@
#include <vector>
+#include "core/fxcrt/fx_memory_wrappers.h"
#include "fxbarcode/BC_TwoDimWriter.h"
class CBC_DataMatrixWriter final : public CBC_TwoDimWriter {
@@ -16,9 +17,8 @@
CBC_DataMatrixWriter();
~CBC_DataMatrixWriter() override;
- std::vector<uint8_t> Encode(const WideString& contents,
- int32_t* pOutWidth,
- int32_t* pOutHeight);
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>>
+ Encode(const WideString& contents, int32_t* pOutWidth, int32_t* pOutHeight);
// CBC_TwoDimWriter
bool SetErrorCorrectionLevel(int32_t level) override;
diff --git a/fxbarcode/datamatrix/BC_DataMatrixWriter_unittest.cpp b/fxbarcode/datamatrix/BC_DataMatrixWriter_unittest.cpp
index fa5d26c..29924d8 100644
--- a/fxbarcode/datamatrix/BC_DataMatrixWriter_unittest.cpp
+++ b/fxbarcode/datamatrix/BC_DataMatrixWriter_unittest.cpp
@@ -40,7 +40,8 @@
1, 1, 1, 1, 1, 1, 1, 1, 1, 1
};
// clang-format on
- std::vector<uint8_t> data = writer.Encode(L"", &width, &height);
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>> data =
+ writer.Encode(L"", &width, &height);
ASSERT_EQ(FX_ArraySize(kExpectedData), data.size());
ASSERT_EQ(kExpectedDimension, width);
ASSERT_EQ(kExpectedDimension, height);
@@ -67,7 +68,8 @@
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
};
// clang-format on
- std::vector<uint8_t> data = writer.Encode(L"helloworld", &width, &height);
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>> data =
+ writer.Encode(L"helloworld", &width, &height);
ASSERT_EQ(FX_ArraySize(kExpectedData), data.size());
ASSERT_EQ(kExpectedDimension, width);
ASSERT_EQ(kExpectedDimension, height);
@@ -90,7 +92,8 @@
1, 1, 1, 1, 1, 1, 1, 1, 1, 1
};
// clang-format on
- std::vector<uint8_t> data = writer.Encode(L"12345", &width, &height);
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>> data =
+ writer.Encode(L"12345", &width, &height);
ASSERT_EQ(FX_ArraySize(kExpectedData), data.size());
ASSERT_EQ(kExpectedDimension, width);
ASSERT_EQ(kExpectedDimension, height);
@@ -121,7 +124,7 @@
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
};
// clang-format on
- std::vector<uint8_t> data =
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>> data =
writer.Encode(L"abcdefghijklmnopqrst", &width, &height);
ASSERT_EQ(FX_ArraySize(kExpectedData), data.size());
ASSERT_EQ(kExpectedDimension, width);
@@ -130,7 +133,8 @@
EXPECT_EQ(kExpectedData[i], data[i]) << i;
}
{
- std::vector<uint8_t> data = writer.Encode(L"hello world", &width, &height);
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>> data =
+ writer.Encode(L"hello world", &width, &height);
ASSERT_TRUE(data.empty());
}
}
@@ -147,7 +151,8 @@
{
static constexpr int kExpectedDimension = 144;
- std::vector<uint8_t> data = writer.Encode(input.c_str(), &width, &height);
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>> data =
+ writer.Encode(input.c_str(), &width, &height);
EXPECT_EQ(20736u, data.size());
EXPECT_EQ(kExpectedDimension, width);
EXPECT_EQ(kExpectedDimension, height);
@@ -158,7 +163,8 @@
{
width = -1;
height = -1;
- std::vector<uint8_t> data = writer.Encode(input.c_str(), &width, &height);
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>> data =
+ writer.Encode(input.c_str(), &width, &height);
EXPECT_EQ(0u, data.size());
EXPECT_EQ(-1, width);
EXPECT_EQ(-1, height);
@@ -177,7 +183,8 @@
{
static constexpr int kExpectedDimension = 144;
- std::vector<uint8_t> data = writer.Encode(input.c_str(), &width, &height);
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>> data =
+ writer.Encode(input.c_str(), &width, &height);
EXPECT_EQ(20736u, data.size());
EXPECT_EQ(kExpectedDimension, width);
EXPECT_EQ(kExpectedDimension, height);
@@ -188,7 +195,8 @@
{
width = -1;
height = -1;
- std::vector<uint8_t> data = writer.Encode(input.c_str(), &width, &height);
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>> data =
+ writer.Encode(input.c_str(), &width, &height);
EXPECT_EQ(0u, data.size());
EXPECT_EQ(-1, width);
EXPECT_EQ(-1, height);
diff --git a/fxbarcode/datamatrix/BC_DefaultPlacement.cpp b/fxbarcode/datamatrix/BC_DefaultPlacement.cpp
index 24d81f1..aedd90c 100644
--- a/fxbarcode/datamatrix/BC_DefaultPlacement.cpp
+++ b/fxbarcode/datamatrix/BC_DefaultPlacement.cpp
@@ -46,7 +46,8 @@
int32_t CBC_DefaultPlacement::getNumcols() {
return m_numcols;
}
-std::vector<uint8_t>& CBC_DefaultPlacement::getBits() {
+std::vector<uint8_t, FxAllocAllocator<uint8_t>>&
+CBC_DefaultPlacement::getBits() {
return m_bits;
}
bool CBC_DefaultPlacement::getBit(int32_t col, int32_t row) {
diff --git a/fxbarcode/datamatrix/BC_DefaultPlacement.h b/fxbarcode/datamatrix/BC_DefaultPlacement.h
index 823d587..7c33aa3 100644
--- a/fxbarcode/datamatrix/BC_DefaultPlacement.h
+++ b/fxbarcode/datamatrix/BC_DefaultPlacement.h
@@ -9,6 +9,7 @@
#include <vector>
+#include "core/fxcrt/fx_memory_wrappers.h"
#include "core/fxcrt/fx_string.h"
class CBC_DefaultPlacement final {
@@ -18,7 +19,7 @@
int32_t getNumrows();
int32_t getNumcols();
- std::vector<uint8_t>& getBits();
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>>& getBits();
bool getBit(int32_t col, int32_t row);
void setBit(int32_t col, int32_t row, bool bit);
bool hasBit(int32_t col, int32_t row);
@@ -28,7 +29,7 @@
WideString m_codewords;
int32_t m_numrows;
int32_t m_numcols;
- std::vector<uint8_t> m_bits;
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>> m_bits;
void module(int32_t row, int32_t col, int32_t pos, int32_t bit);
void utah(int32_t row, int32_t col, int32_t pos);
void corner1(int32_t pos);
diff --git a/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.cpp b/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.cpp
index 70e7cd9..e7cb1f1 100644
--- a/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.cpp
+++ b/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.cpp
@@ -33,10 +33,12 @@
CBC_BarcodeMatrix::~CBC_BarcodeMatrix() {}
-std::vector<uint8_t> CBC_BarcodeMatrix::toBitArray() {
- std::vector<uint8_t> bitArray(m_width * m_height);
+std::vector<uint8_t, FxAllocAllocator<uint8_t>>
+CBC_BarcodeMatrix::toBitArray() {
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>> bitArray(m_width * m_height);
for (size_t i = 0; i < m_height; ++i) {
- std::vector<uint8_t>& bytearray = m_matrix[i]->getRow();
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>>& bytearray =
+ m_matrix[i]->getRow();
for (size_t j = 0; j < m_width; ++j)
bitArray[i * m_width + j] = bytearray[j];
}
diff --git a/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.h b/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.h
index d059cee..cb88c62 100644
--- a/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.h
+++ b/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.h
@@ -10,6 +10,8 @@
#include <memory>
#include <vector>
+#include "core/fxcrt/fx_memory_wrappers.h"
+
class CBC_BarcodeRow;
class CBC_BarcodeMatrix final {
@@ -20,7 +22,7 @@
CBC_BarcodeRow* getRow(size_t row) const { return m_matrix[row].get(); }
size_t getWidth() const { return m_width; }
size_t getHeight() const { return m_height; }
- std::vector<uint8_t> toBitArray();
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>> toBitArray();
private:
std::vector<std::unique_ptr<CBC_BarcodeRow>> m_matrix;
diff --git a/fxbarcode/pdf417/BC_PDF417BarcodeRow.cpp b/fxbarcode/pdf417/BC_PDF417BarcodeRow.cpp
index 65c27de..eb425a9 100644
--- a/fxbarcode/pdf417/BC_PDF417BarcodeRow.cpp
+++ b/fxbarcode/pdf417/BC_PDF417BarcodeRow.cpp
@@ -34,6 +34,6 @@
m_currentLocation += width;
}
-std::vector<uint8_t>& CBC_BarcodeRow::getRow() {
+std::vector<uint8_t, FxAllocAllocator<uint8_t>>& CBC_BarcodeRow::getRow() {
return m_row;
}
diff --git a/fxbarcode/pdf417/BC_PDF417BarcodeRow.h b/fxbarcode/pdf417/BC_PDF417BarcodeRow.h
index 07ebbd7..4b7b6f0 100644
--- a/fxbarcode/pdf417/BC_PDF417BarcodeRow.h
+++ b/fxbarcode/pdf417/BC_PDF417BarcodeRow.h
@@ -11,16 +11,18 @@
#include <vector>
+#include "core/fxcrt/fx_memory_wrappers.h"
+
class CBC_BarcodeRow final {
public:
explicit CBC_BarcodeRow(size_t width);
~CBC_BarcodeRow();
void addBar(bool black, int32_t width);
- std::vector<uint8_t>& getRow();
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>>& getRow();
private:
- std::vector<uint8_t> m_row;
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>> m_row;
int32_t m_currentLocation;
};
diff --git a/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.cpp b/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.cpp
index 0570338..65eef10 100644
--- a/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.cpp
+++ b/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.cpp
@@ -89,7 +89,8 @@
result += ch;
}
- std::vector<uint8_t> byteArr(bytes.begin(), bytes.end());
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>> byteArr(bytes.begin(),
+ bytes.end());
len = result.GetLength();
WideString sb;
sb.Reserve(len);
@@ -354,7 +355,7 @@
Optional<size_t> CBC_PDF417HighLevelEncoder::DetermineConsecutiveBinaryCount(
WideString msg,
- std::vector<uint8_t>* bytes,
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>>* bytes,
size_t startpos) {
size_t len = msg.GetLength();
size_t idx = startpos;
diff --git a/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.h b/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.h
index df1cd54..b6dd1b9 100644
--- a/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.h
+++ b/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.h
@@ -9,6 +9,7 @@
#include <vector>
+#include "core/fxcrt/fx_memory_wrappers.h"
#include "core/fxcrt/fx_string.h"
#include "fxbarcode/pdf417/BC_PDF417.h"
#include "third_party/base/optional.h"
@@ -44,7 +45,7 @@
static size_t DetermineConsecutiveTextCount(WideString msg, size_t startpos);
static Optional<size_t> DetermineConsecutiveBinaryCount(
WideString msg,
- std::vector<uint8_t>* bytes,
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>>* bytes,
size_t startpos);
friend class PDF417HighLevelEncoderTest_ConsecutiveBinaryCount_Test;
diff --git a/fxbarcode/pdf417/BC_PDF417Writer.cpp b/fxbarcode/pdf417/BC_PDF417Writer.cpp
index f9f3624..4ef6b7e 100644
--- a/fxbarcode/pdf417/BC_PDF417Writer.cpp
+++ b/fxbarcode/pdf417/BC_PDF417Writer.cpp
@@ -43,10 +43,11 @@
return true;
}
-std::vector<uint8_t> CBC_PDF417Writer::Encode(WideStringView contents,
- int32_t* pOutWidth,
- int32_t* pOutHeight) {
- std::vector<uint8_t> results;
+std::vector<uint8_t, FxAllocAllocator<uint8_t>> CBC_PDF417Writer::Encode(
+ WideStringView contents,
+ int32_t* pOutWidth,
+ int32_t* pOutHeight) {
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>> results;
CBC_PDF417 encoder;
int32_t col = (m_Width / m_ModuleWidth - 69) / 17;
int32_t row = m_Height / (m_ModuleWidth * 20);
@@ -60,7 +61,8 @@
return results;
CBC_BarcodeMatrix* barcodeMatrix = encoder.getBarcodeMatrix();
- std::vector<uint8_t> matrixData = barcodeMatrix->toBitArray();
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>> matrixData =
+ barcodeMatrix->toBitArray();
int32_t matrixWidth = barcodeMatrix->getWidth();
int32_t matrixHeight = barcodeMatrix->getHeight();
@@ -70,15 +72,17 @@
}
*pOutWidth = matrixWidth;
*pOutHeight = matrixHeight;
- results = pdfium::Vector2D<uint8_t>(*pOutWidth, *pOutHeight);
+ results = pdfium::Vector2D<uint8_t, FxAllocAllocator<uint8_t>>(*pOutWidth,
+ *pOutHeight);
memcpy(results.data(), matrixData.data(), *pOutWidth * *pOutHeight);
return results;
}
-void CBC_PDF417Writer::RotateArray(std::vector<uint8_t>* bitarray,
- int32_t height,
- int32_t width) {
- std::vector<uint8_t> temp = *bitarray;
+void CBC_PDF417Writer::RotateArray(
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>>* bitarray,
+ int32_t height,
+ int32_t width) {
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>> temp = *bitarray;
for (int32_t ii = 0; ii < height; ii++) {
int32_t inverseii = height - ii - 1;
for (int32_t jj = 0; jj < width; jj++) {
diff --git a/fxbarcode/pdf417/BC_PDF417Writer.h b/fxbarcode/pdf417/BC_PDF417Writer.h
index 10f069a..c7f75ef 100644
--- a/fxbarcode/pdf417/BC_PDF417Writer.h
+++ b/fxbarcode/pdf417/BC_PDF417Writer.h
@@ -9,6 +9,7 @@
#include <vector>
+#include "core/fxcrt/fx_memory_wrappers.h"
#include "core/fxcrt/fx_string.h"
#include "core/fxcrt/fx_system.h"
#include "fxbarcode/BC_TwoDimWriter.h"
@@ -18,15 +19,14 @@
CBC_PDF417Writer();
~CBC_PDF417Writer() override;
- std::vector<uint8_t> Encode(WideStringView contents,
- int32_t* pOutWidth,
- int32_t* pOutHeight);
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>>
+ Encode(WideStringView contents, int32_t* pOutWidth, int32_t* pOutHeight);
// CBC_TwoDimWriter
bool SetErrorCorrectionLevel(int32_t level) override;
private:
- void RotateArray(std::vector<uint8_t>* bitarray,
+ void RotateArray(std::vector<uint8_t, FxAllocAllocator<uint8_t>>* bitarray,
int32_t width,
int32_t height);
};
diff --git a/fxbarcode/pdf417/BC_PDF417Writer_unittest.cpp b/fxbarcode/pdf417/BC_PDF417Writer_unittest.cpp
index 1c09d78..99ed6df 100644
--- a/fxbarcode/pdf417/BC_PDF417Writer_unittest.cpp
+++ b/fxbarcode/pdf417/BC_PDF417Writer_unittest.cpp
@@ -413,7 +413,8 @@
1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1,
0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1,
1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1};
- std::vector<uint8_t> data = writer.Encode(L"", &width, &height);
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>> data =
+ writer.Encode(L"", &width, &height);
ASSERT_EQ(FX_ArraySize(kExpectedData), data.size());
ASSERT_EQ(kExpectedWidth, width);
ASSERT_EQ(kExpectedHeight, height);
@@ -810,7 +811,8 @@
1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0,
0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1,
1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1};
- std::vector<uint8_t> data = writer.Encode(L"hello world", &width, &height);
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>> data =
+ writer.Encode(L"hello world", &width, &height);
ASSERT_EQ(FX_ArraySize(kExpectedData), data.size());
ASSERT_EQ(kExpectedWidth, width);
ASSERT_EQ(kExpectedHeight, height);
diff --git a/fxbarcode/qrcode/BC_QRCodeWriter.cpp b/fxbarcode/qrcode/BC_QRCodeWriter.cpp
index 1eead62..cae71bc 100644
--- a/fxbarcode/qrcode/BC_QRCodeWriter.cpp
+++ b/fxbarcode/qrcode/BC_QRCodeWriter.cpp
@@ -43,11 +43,12 @@
return true;
}
-std::vector<uint8_t> CBC_QRCodeWriter::Encode(WideStringView contents,
- int32_t ecLevel,
- int32_t* pOutWidth,
- int32_t* pOutHeight) {
- std::vector<uint8_t> results;
+std::vector<uint8_t, FxAllocAllocator<uint8_t>> CBC_QRCodeWriter::Encode(
+ WideStringView contents,
+ int32_t ecLevel,
+ int32_t* pOutWidth,
+ int32_t* pOutHeight) {
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>> results;
CBC_QRCoderErrorCorrectionLevel* ec = nullptr;
switch (ecLevel) {
case 0:
@@ -71,7 +72,8 @@
*pOutWidth = qr.GetMatrixWidth();
*pOutHeight = qr.GetMatrixWidth();
- results = pdfium::Vector2D<uint8_t>(*pOutWidth, *pOutHeight);
+ results = pdfium::Vector2D<uint8_t, FxAllocAllocator<uint8_t>>(*pOutWidth,
+ *pOutHeight);
memcpy(results.data(), qr.GetMatrix()->GetArray().data(),
*pOutWidth * *pOutHeight);
return results;
diff --git a/fxbarcode/qrcode/BC_QRCodeWriter.h b/fxbarcode/qrcode/BC_QRCodeWriter.h
index 3f2cca0..3031927 100644
--- a/fxbarcode/qrcode/BC_QRCodeWriter.h
+++ b/fxbarcode/qrcode/BC_QRCodeWriter.h
@@ -9,6 +9,7 @@
#include <vector>
+#include "core/fxcrt/fx_memory_wrappers.h"
#include "fxbarcode/BC_TwoDimWriter.h"
class CBC_QRCodeWriter final : public CBC_TwoDimWriter {
@@ -16,10 +17,11 @@
CBC_QRCodeWriter();
~CBC_QRCodeWriter() override;
- std::vector<uint8_t> Encode(WideStringView contents,
- int32_t ecLevel,
- int32_t* pOutWidth,
- int32_t* pOutHeight);
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>> Encode(
+ WideStringView contents,
+ int32_t ecLevel,
+ int32_t* pOutWidth,
+ int32_t* pOutHeight);
// CBC_TwoDimWriter
bool SetErrorCorrectionLevel(int32_t level) override;
diff --git a/fxbarcode/qrcode/BC_QRCodeWriter_unittest.cpp b/fxbarcode/qrcode/BC_QRCodeWriter_unittest.cpp
index 709d497..6edbc87 100644
--- a/fxbarcode/qrcode/BC_QRCodeWriter_unittest.cpp
+++ b/fxbarcode/qrcode/BC_QRCodeWriter_unittest.cpp
@@ -51,7 +51,8 @@
1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1
};
// clang-format on
- std::vector<uint8_t> data = writer.Encode(L"", 0, &width, &height);
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>> data =
+ writer.Encode(L"", 0, &width, &height);
ASSERT_EQ(FX_ArraySize(kExpectedData), data.size());
ASSERT_EQ(kExpectedDimension, width);
ASSERT_EQ(kExpectedDimension, height);
@@ -85,7 +86,8 @@
1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1
};
// clang-format on
- std::vector<uint8_t> data = writer.Encode(L"", 1, &width, &height);
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>> data =
+ writer.Encode(L"", 1, &width, &height);
ASSERT_EQ(FX_ArraySize(kExpectedData), data.size());
ASSERT_EQ(kExpectedDimension, width);
ASSERT_EQ(kExpectedDimension, height);
@@ -119,7 +121,8 @@
1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0
};
// clang-format on
- std::vector<uint8_t> data = writer.Encode(L"", 2, &width, &height);
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>> data =
+ writer.Encode(L"", 2, &width, &height);
ASSERT_EQ(FX_ArraySize(kExpectedData), data.size());
ASSERT_EQ(kExpectedDimension, width);
ASSERT_EQ(kExpectedDimension, height);
@@ -153,7 +156,8 @@
1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0
};
// clang-format on
- std::vector<uint8_t> data = writer.Encode(L"", 3, &width, &height);
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>> data =
+ writer.Encode(L"", 3, &width, &height);
ASSERT_EQ(FX_ArraySize(kExpectedData), data.size());
ASSERT_EQ(kExpectedDimension, width);
ASSERT_EQ(kExpectedDimension, height);
@@ -187,7 +191,7 @@
1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0
};
// clang-format on
- std::vector<uint8_t> data =
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>> data =
writer.Encode(L"hello world", 0, &width, &height);
ASSERT_EQ(FX_ArraySize(kExpectedData), data.size());
ASSERT_EQ(kExpectedDimension, width);
@@ -222,7 +226,7 @@
1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0
};
// clang-format on
- std::vector<uint8_t> data =
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>> data =
writer.Encode(L"hello world", 1, &width, &height);
ASSERT_EQ(FX_ArraySize(kExpectedData), data.size());
ASSERT_EQ(kExpectedDimension, width);
@@ -260,7 +264,7 @@
0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1,
1};
- std::vector<uint8_t> data =
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>> data =
writer.Encode(L"hello world", 2, &width, &height);
ASSERT_EQ(FX_ArraySize(kExpectedData), data.size());
ASSERT_EQ(kExpectedDimension, width);
@@ -298,7 +302,7 @@
0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1,
1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1,
1};
- std::vector<uint8_t> data =
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>> data =
writer.Encode(L"hello world", 3, &width, &height);
ASSERT_EQ(FX_ArraySize(kExpectedData), data.size());
ASSERT_EQ(kExpectedDimension, width);
diff --git a/fxbarcode/qrcode/BC_QRCoderBitVector.h b/fxbarcode/qrcode/BC_QRCoderBitVector.h
index 9b8af81..a0f29fe 100644
--- a/fxbarcode/qrcode/BC_QRCoderBitVector.h
+++ b/fxbarcode/qrcode/BC_QRCoderBitVector.h
@@ -12,6 +12,8 @@
#include <vector>
+#include "core/fxcrt/fx_memory_wrappers.h"
+
class CBC_QRCoderBitVector {
public:
CBC_QRCoderBitVector();
@@ -31,7 +33,7 @@
void AppendByte(int8_t value);
size_t m_sizeInBits = 0;
- std::vector<uint8_t> m_array;
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>> m_array;
};
#endif // FXBARCODE_QRCODE_BC_QRCODERBITVECTOR_H_
diff --git a/fxbarcode/qrcode/BC_QRCoderEncoder.cpp b/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
index be02f5b..4cb6337 100644
--- a/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
+++ b/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
@@ -27,6 +27,7 @@
#include <utility>
#include <vector>
+#include "core/fxcrt/fx_memory_wrappers.h"
#include "fxbarcode/common/BC_CommonByteMatrix.h"
#include "fxbarcode/common/reedsolomon/BC_ReedSolomon.h"
#include "fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h"
@@ -47,8 +48,8 @@
CBC_ReedSolomonGF256* g_QRCodeField = nullptr;
struct QRCoderBlockPair {
- std::vector<uint8_t> data;
- std::vector<uint8_t> ecc;
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>> data;
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>> ecc;
};
// This is a mapping for an ASCII table, starting at an index of 32.
@@ -140,7 +141,7 @@
}
bool AppendKanjiBytes(const ByteString& content, CBC_QRCoderBitVector* bits) {
- std::vector<uint8_t> bytes;
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>> bytes;
uint32_t value = 0;
// TODO(thestig): This is wrong, as |bytes| is empty.
for (size_t i = 0; i < bytes.size(); i += 2) {
@@ -224,18 +225,19 @@
return false;
}
-std::vector<uint8_t> GenerateECBytes(pdfium::span<const uint8_t> dataBytes,
- size_t numEcBytesInBlock) {
+std::vector<uint8_t, FxAllocAllocator<uint8_t>> GenerateECBytes(
+ pdfium::span<const uint8_t> dataBytes,
+ size_t numEcBytesInBlock) {
// If |numEcBytesInBlock| is 0, the encoder will fail anyway.
ASSERT(numEcBytesInBlock > 0);
std::vector<int32_t> toEncode(dataBytes.size() + numEcBytesInBlock);
std::copy(dataBytes.begin(), dataBytes.end(), toEncode.begin());
- std::vector<uint8_t> ecBytes;
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>> ecBytes;
CBC_ReedSolomonEncoder encoder(g_QRCodeField);
if (encoder.Encode(&toEncode, numEcBytesInBlock)) {
- ecBytes = std::vector<uint8_t>(toEncode.begin() + dataBytes.size(),
- toEncode.end());
+ ecBytes = std::vector<uint8_t, FxAllocAllocator<uint8_t>>(
+ toEncode.begin() + dataBytes.size(), toEncode.end());
ASSERT(ecBytes.size() == static_cast<size_t>(numEcBytesInBlock));
}
return ecBytes;
@@ -365,10 +367,11 @@
if (numDataBytesInBlock < 0 || numEcBytesInBlock <= 0)
return false;
- std::vector<uint8_t> dataBytes(numDataBytesInBlock);
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>> dataBytes(
+ numDataBytesInBlock);
memcpy(dataBytes.data(), bits->GetArray() + dataBytesOffset,
numDataBytesInBlock);
- std::vector<uint8_t> ecBytes =
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>> ecBytes =
GenerateECBytes(dataBytes, numEcBytesInBlock);
if (ecBytes.empty())
return false;
@@ -384,14 +387,16 @@
for (size_t x = 0; x < maxNumDataBytes; x++) {
for (size_t j = 0; j < blocks.size(); j++) {
- const std::vector<uint8_t>& dataBytes = blocks[j].data;
+ const std::vector<uint8_t, FxAllocAllocator<uint8_t>>& dataBytes =
+ blocks[j].data;
if (x < dataBytes.size())
result->AppendBits(dataBytes[x], 8);
}
}
for (size_t y = 0; y < maxNumEcBytes; y++) {
for (size_t l = 0; l < blocks.size(); l++) {
- const std::vector<uint8_t>& ecBytes = blocks[l].ecc;
+ const std::vector<uint8_t, FxAllocAllocator<uint8_t>>& ecBytes =
+ blocks[l].ecc;
if (y < ecBytes.size())
result->AppendBits(ecBytes[y], 8);
}