Prepare more files for update to pdfium::span<>
Update files which were missed in the last go-around. In particular,
avoid using dynamic_extent with two-arg subspan (deviation from std::
spec in base::span<> that eliminates branching).
Bug: 42271100
Change-Id: I2080257bb2e8a94ddbf9246c9ba1ddf2cb14fb17
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/130993
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/font/cpdf_cidfont.cpp b/core/fpdfapi/font/cpdf_cidfont.cpp
index dee643a..ee18859 100644
--- a/core/fpdfapi/font/cpdf_cidfont.cpp
+++ b/core/fpdfapi/font/cpdf_cidfont.cpp
@@ -350,7 +350,8 @@
wchar_t unicode;
size_t ret = FX_MultiByteToWideChar(
kCharsetCodePages[static_cast<size_t>(cmap_->GetCoding())],
- ByteStringView(pdfium::make_span(sequence).first(charsize)),
+ ByteStringView(
+ pdfium::make_span(sequence).first(static_cast<size_t>(charsize))),
pdfium::span_from_ref(unicode));
return ret == 1 ? unicode : 0;
#else
diff --git a/core/fxcodec/fax/faxmodule.cpp b/core/fxcodec/fax/faxmodule.cpp
index 9e91c0a..28d3e8d 100644
--- a/core/fxcodec/fax/faxmodule.cpp
+++ b/core/fxcodec/fax/faxmodule.cpp
@@ -866,7 +866,8 @@
line_buf_[0] = last_byte;
pdfium::span<const uint8_t> scan_line = src_->GetScanline(i);
FaxEncode2DLine(scan_line);
- dest_buf_.AppendSpan(pdfium::make_span(line_buf_).first(dest_bitpos_ / 8));
+ dest_buf_.AppendSpan(pdfium::make_span(line_buf_).first(
+ static_cast<size_t>(dest_bitpos_ / 8)));
last_byte = line_buf_[dest_bitpos_ / 8];
dest_bitpos_ %= 8;
ref_line_span_ = scan_line;
diff --git a/core/fxcodec/jpeg/jpegmodule.cpp b/core/fxcodec/jpeg/jpegmodule.cpp
index f86ee5a..b5d8a57 100644
--- a/core/fxcodec/jpeg/jpegmodule.cpp
+++ b/core/fxcodec/jpeg/jpegmodule.cpp
@@ -451,14 +451,14 @@
for (uint32_t i = 0; i < width; i++) {
ReverseCopy3Bytes(dest_scan, src_scan.data());
dest_scan += 3;
- src_scan = src_scan.subspan(bytes_per_pixel);
+ src_scan = src_scan.subspan(static_cast<size_t>(bytes_per_pixel));
}
});
} else {
UNSAFE_TODO({
for (uint32_t i = 0; i < pitch; i++) {
*dest_scan++ = ~src_scan.front();
- src_scan = src_scan.subspan(1);
+ src_scan = src_scan.subspan<1u>();
}
});
}
diff --git a/core/fxcrt/fixed_size_data_vector.h b/core/fxcrt/fixed_size_data_vector.h
index 5e8c8c9..0d87dd7 100644
--- a/core/fxcrt/fixed_size_data_vector.h
+++ b/core/fxcrt/fixed_size_data_vector.h
@@ -112,12 +112,14 @@
}
// Convenience methods to slice the vector into spans.
- pdfium::span<T> subspan(size_t offset,
- size_t count = pdfium::dynamic_extent) {
+ pdfium::span<T> subspan(size_t offset) { return span().subspan(offset); }
+ pdfium::span<const T> subspan(size_t offset) const {
+ return span().subspan(offset);
+ }
+ pdfium::span<T> subspan(size_t offset, size_t count) {
return span().subspan(offset, count);
}
- pdfium::span<const T> subspan(size_t offset,
- size_t count = pdfium::dynamic_extent) const {
+ pdfium::span<const T> subspan(size_t offset, size_t count) const {
return span().subspan(offset, count);
}
diff --git a/core/fxcrt/fx_coordinates.cpp b/core/fxcrt/fx_coordinates.cpp
index 32b52d7..385b13c 100644
--- a/core/fxcrt/fx_coordinates.cpp
+++ b/core/fxcrt/fx_coordinates.cpp
@@ -146,7 +146,7 @@
float max_x = pPoints.front().x;
float min_y = pPoints.front().y;
float max_y = pPoints.front().y;
- for (const auto& point : pPoints.subspan(1)) {
+ for (const auto& point : pPoints.subspan<1u>()) {
min_x = std::min(min_x, point.x);
max_x = std::max(max_x, point.x);
min_y = std::min(min_y, point.y);
diff --git a/core/fxcrt/zip_unittest.cpp b/core/fxcrt/zip_unittest.cpp
index 40666c2..1ab23c3 100644
--- a/core/fxcrt/zip_unittest.cpp
+++ b/core/fxcrt/zip_unittest.cpp
@@ -68,7 +68,7 @@
// Test that ordering of args doesn't matter, except for the size
// determination.
int output[4] = {};
- auto sub_output = pdfium::make_span(output).first(3);
+ auto sub_output = pdfium::make_span(output).first<3u>();
for (auto [out, in] : Zip(sub_output, stuff)) {
out = in;
}
@@ -99,7 +99,7 @@
// Test that ordering of args doesn't matter, except for the size
// determination.
int output[4] = {};
- auto sub_output = pdfium::make_span(output).first(3);
+ auto sub_output = pdfium::make_span(output).first<3u>();
for (auto [out, in1, in2] : Zip(sub_output, stuff1, stuff2)) {
out = in1 + in2;
}
diff --git a/core/fxge/dib/cfx_dibbase.cpp b/core/fxge/dib/cfx_dibbase.cpp
index fa553fa..8680911 100644
--- a/core/fxge/dib/cfx_dibbase.cpp
+++ b/core/fxge/dib/cfx_dibbase.cpp
@@ -46,7 +46,7 @@
dest_buf.subspan(Fx2DSizeOrDie(row, dest_pitch)));
auto src_span =
src_bitmap->GetScanlineAs<FX_BGR_STRUCT<uint8_t>>(src_top + row)
- .subspan(src_left);
+ .subspan(static_cast<size_t>(src_left));
for (auto [input, output] : fxcrt::Zip(src_span, dest_span)) {
output.blue = input.blue;
output.green = input.green;
@@ -69,7 +69,7 @@
dest_buf.subspan(Fx2DSizeOrDie(row, dest_pitch)));
auto src_span =
src_bitmap->GetScanlineAs<FX_BGRA_STRUCT<uint8_t>>(src_top + row)
- .subspan(src_left);
+ .subspan(static_cast<size_t>(src_left));
for (auto [input, output] : fxcrt::Zip(src_span, dest_span)) {
auto unpremultiplied_input = UnPreMultiplyColor(input);
output.blue = unpremultiplied_input.blue;
diff --git a/core/fxge/dib/cfx_scanlinecompositor.cpp b/core/fxge/dib/cfx_scanlinecompositor.cpp
index 566d28d..fe7da3f 100644
--- a/core/fxge/dib/cfx_scanlinecompositor.cpp
+++ b/core/fxge/dib/cfx_scanlinecompositor.cpp
@@ -2623,7 +2623,7 @@
auto src_span =
fxcrt::reinterpret_span<const FX_BGRA_STRUCT<uint8_t>>(src_scan).first(
- width);
+ static_cast<size_t>(width));
switch (dest_format_) {
case FXDIB_Format::kInvalid:
diff --git a/core/fxge/win32/cfx_psrenderer.cpp b/core/fxge/win32/cfx_psrenderer.cpp
index e8a9268..6916666 100644
--- a/core/fxge/win32/cfx_psrenderer.cpp
+++ b/core/fxge/win32/cfx_psrenderer.cpp
@@ -918,7 +918,9 @@
result.data.resize(safe_size.ValueOrDie());
auto dest_span = pdfium::make_span(result.data);
for (int row = 0; row < height; row++) {
- fxcrt::Copy(src->GetScanline(row), dest_span.subspan(row * pitch, pitch));
+ fxcrt::Copy(src->GetScanline(row),
+ dest_span.subspan(static_cast<size_t>(row * pitch),
+ static_cast<size_t>(pitch)));
}
return result;
}