Use spans in CBC_BarcodeMatrix and CBC_BarcodeRow.

- Copy 1 row at a time using spancpy().
- Return a span from CBC_BarcodeRow instead the vector.

Change-Id: I0227682276286bbc9736572a6d04c371578e60dc
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/96412
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.cpp b/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.cpp
index f0c4b0f..c29f43a 100644
--- a/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.cpp
+++ b/fxbarcode/pdf417/BC_PDF417BarcodeMatrix.cpp
@@ -25,6 +25,7 @@
 #include <stdint.h>
 
 #include "core/fxcrt/data_vector.h"
+#include "core/fxcrt/span_util.h"
 #include "fxbarcode/pdf417/BC_PDF417BarcodeRow.h"
 
 CBC_BarcodeMatrix::CBC_BarcodeMatrix(size_t width, size_t height)
@@ -37,11 +38,9 @@
 CBC_BarcodeMatrix::~CBC_BarcodeMatrix() = default;
 
 DataVector<uint8_t> CBC_BarcodeMatrix::toBitArray() {
-  DataVector<uint8_t> bitArray(m_width * m_height);
-  for (size_t i = 0; i < m_height; ++i) {
-    const auto& bytearray = m_matrix[i]->GetRow();
-    for (size_t j = 0; j < m_width; ++j)
-      bitArray[i * m_width + j] = bytearray[j];
-  }
-  return bitArray;
+  DataVector<uint8_t> bit_array(m_width * m_height);
+  pdfium::span<uint8_t> bit_array_span(bit_array);
+  for (size_t i = 0; i < m_height; ++i)
+    fxcrt::spancpy(bit_array_span.subspan(i * m_width), m_matrix[i]->GetRow());
+  return bit_array;
 }
diff --git a/fxbarcode/pdf417/BC_PDF417BarcodeRow.h b/fxbarcode/pdf417/BC_PDF417BarcodeRow.h
index 607e225..5322e5b 100644
--- a/fxbarcode/pdf417/BC_PDF417BarcodeRow.h
+++ b/fxbarcode/pdf417/BC_PDF417BarcodeRow.h
@@ -10,6 +10,7 @@
 #include <stdint.h>
 
 #include "core/fxcrt/data_vector.h"
+#include "third_party/base/span.h"
 
 class CBC_BarcodeRow final {
  public:
@@ -17,7 +18,7 @@
   ~CBC_BarcodeRow();
 
   void AddBar(bool black, size_t width);
-  const DataVector<uint8_t>& GetRow() const { return row_; }
+  pdfium::span<const uint8_t> GetRow() const { return row_; }
 
  private:
   DataVector<uint8_t> row_;