Use FixedDataVector in fxbarcode/ when applicable.

Switch form DataVector to FixedDataVector when the container size does
not change. Use more spans as a result.

Change-Id: Ie90d82826f407e331a1a9136274c3b386e3eb60c
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/98173
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/fxbarcode/common/BC_CommonBitMatrix.cpp b/fxbarcode/common/BC_CommonBitMatrix.cpp
index 7b94aa3..285cf24 100644
--- a/fxbarcode/common/BC_CommonBitMatrix.cpp
+++ b/fxbarcode/common/BC_CommonBitMatrix.cpp
@@ -22,26 +22,24 @@
 
 #include "fxbarcode/common/BC_CommonBitMatrix.h"
 
-#include "core/fxcrt/data_vector.h"
+#include "core/fxcrt/fixed_zeroed_data_vector.h"
 #include "third_party/base/check_op.h"
 
 CBC_CommonBitMatrix::CBC_CommonBitMatrix(size_t width, size_t height)
     : m_height(height), m_rowSize((width + 31) >> 5) {
   static constexpr int32_t kMaxBits = 1024 * 1024 * 1024;  // 1 Gb.
   CHECK_LT(m_rowSize, kMaxBits / m_height);
-  m_bits.resize(m_rowSize * m_height);
+  m_bits = FixedZeroedDataVector<uint32_t>(m_rowSize * m_height);
 }
 
 CBC_CommonBitMatrix::~CBC_CommonBitMatrix() = default;
 
 bool CBC_CommonBitMatrix::Get(size_t x, size_t y) const {
   size_t offset = y * m_rowSize + (x >> 5);
-  CHECK_LT(offset, m_rowSize * m_height);
-  return ((m_bits[offset] >> (x & 0x1f)) & 1) != 0;
+  return ((m_bits.span()[offset] >> (x & 0x1f)) & 1) != 0;
 }
 
 void CBC_CommonBitMatrix::Set(size_t x, size_t y) {
   size_t offset = y * m_rowSize + (x >> 5);
-  CHECK_LT(offset, m_rowSize * m_height);
-  m_bits[offset] |= 1u << (x & 0x1f);
+  m_bits.writable_span()[offset] |= 1u << (x & 0x1f);
 }
diff --git a/fxbarcode/common/BC_CommonBitMatrix.h b/fxbarcode/common/BC_CommonBitMatrix.h
index 1922935..aa8e916 100644
--- a/fxbarcode/common/BC_CommonBitMatrix.h
+++ b/fxbarcode/common/BC_CommonBitMatrix.h
@@ -10,7 +10,7 @@
 #include <stddef.h>
 #include <stdint.h>
 
-#include "core/fxcrt/data_vector.h"
+#include "core/fxcrt/fixed_zeroed_data_vector.h"
 
 class CBC_CommonBitMatrix {
  public:
@@ -23,7 +23,7 @@
  private:
   const size_t m_height;
   const size_t m_rowSize;
-  DataVector<uint32_t> m_bits;
+  FixedZeroedDataVector<uint32_t> m_bits;
 };
 
 #endif  // FXBARCODE_COMMON_BC_COMMONBITMATRIX_H_
diff --git a/fxbarcode/datamatrix/BC_ErrorCorrection.cpp b/fxbarcode/datamatrix/BC_ErrorCorrection.cpp
index d6b4d5f..aef9fb3 100644
--- a/fxbarcode/datamatrix/BC_ErrorCorrection.cpp
+++ b/fxbarcode/datamatrix/BC_ErrorCorrection.cpp
@@ -27,7 +27,7 @@
 #include <algorithm>
 #include <vector>
 
-#include "core/fxcrt/data_vector.h"
+#include "core/fxcrt/fixed_zeroed_data_vector.h"
 #include "fxbarcode/datamatrix/BC_Encoder.h"
 #include "fxbarcode/datamatrix/BC_SymbolInfo.h"
 #include "third_party/base/check.h"
@@ -156,28 +156,29 @@
   if (table >= kFactorTableNum)
     return WideString();
 
-  DataVector<uint16_t> ecc(numECWords);
+  FixedZeroedDataVector<uint16_t> ecc(numECWords);
+  pdfium::span<uint16_t> ecc_span = ecc.writable_span();
   for (size_t i = 0; i < len; ++i) {
-    uint16_t m = ecc[numECWords - 1] ^ codewords[i];
+    uint16_t m = ecc_span[numECWords - 1] ^ codewords[i];
     for (int32_t j = numECWords - 1; j > 0; --j) {
       if (m != 0 && FACTORS[table][j] != 0) {
-        ecc[j] = static_cast<uint16_t>(
-            ecc[j - 1] ^ ALOG[(LOG[m] + LOG[FACTORS[table][j]]) % 255]);
+        ecc_span[j] = static_cast<uint16_t>(
+            ecc_span[j - 1] ^ ALOG[(LOG[m] + LOG[FACTORS[table][j]]) % 255]);
       } else {
-        ecc[j] = ecc[j - 1];
+        ecc_span[j] = ecc_span[j - 1];
       }
     }
     if (m != 0 && FACTORS[table][0] != 0) {
-      ecc[0] =
+      ecc_span[0] =
           static_cast<uint16_t>(ALOG[(LOG[m] + LOG[FACTORS[table][0]]) % 255]);
     } else {
-      ecc[0] = 0;
+      ecc_span[0] = 0;
     }
   }
   WideString strecc;
   strecc.Reserve(numECWords);
   for (size_t i = 0; i < numECWords; ++i)
-    strecc.InsertAtBack(static_cast<wchar_t>(ecc[numECWords - i - 1]));
+    strecc.InsertAtBack(static_cast<wchar_t>(ecc_span[numECWords - i - 1]));
 
   DCHECK(!strecc.IsEmpty());
   return strecc;
diff --git a/fxbarcode/pdf417/BC_PDF417BarcodeRow.cpp b/fxbarcode/pdf417/BC_PDF417BarcodeRow.cpp
index 4a1f6dd..d8dd44e 100644
--- a/fxbarcode/pdf417/BC_PDF417BarcodeRow.cpp
+++ b/fxbarcode/pdf417/BC_PDF417BarcodeRow.cpp
@@ -22,13 +22,16 @@
 
 #include "fxbarcode/pdf417/BC_PDF417BarcodeRow.h"
 
-#include <algorithm>
+#include "core/fxcrt/span_util.h"
+#include "third_party/base/check_op.h"
 
 CBC_BarcodeRow::CBC_BarcodeRow(size_t width) : row_(width) {}
 
 CBC_BarcodeRow::~CBC_BarcodeRow() = default;
 
 void CBC_BarcodeRow::AddBar(bool black, size_t width) {
-  std::fill_n(row_.begin() + offset_, width, black ? 1 : 0);
+  pdfium::span<uint8_t> available = row_.writable_span().subspan(offset_);
+  CHECK_LE(width, available.size());
+  fxcrt::spanset(available.first(width), black ? 1 : 0);
   offset_ += width;
 }
diff --git a/fxbarcode/pdf417/BC_PDF417BarcodeRow.h b/fxbarcode/pdf417/BC_PDF417BarcodeRow.h
index 5322e5b..53e5c68 100644
--- a/fxbarcode/pdf417/BC_PDF417BarcodeRow.h
+++ b/fxbarcode/pdf417/BC_PDF417BarcodeRow.h
@@ -9,7 +9,7 @@
 
 #include <stdint.h>
 
-#include "core/fxcrt/data_vector.h"
+#include "core/fxcrt/fixed_zeroed_data_vector.h"
 #include "third_party/base/span.h"
 
 class CBC_BarcodeRow final {
@@ -21,7 +21,7 @@
   pdfium::span<const uint8_t> GetRow() const { return row_; }
 
  private:
-  DataVector<uint8_t> row_;
+  FixedZeroedDataVector<uint8_t> row_;
   size_t offset_ = 0;
 };