Pass const-ref to CPDF_PageContentGenerator::UpdateContentStreams()
Prefer const-ref over pointer for objects that are not mutated by
the callee. Found by overzealous grep while looking for pointers to
std::unique_ptr<>.
We can now avoid a local in the caller since we can just pass a rvalue
without having to apply & (address-of).
Change-Id: I7a0f6d38edee02f006c40434be4756d514135094
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/77090
Reviewed-by: Hui Yingst <nigi@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
index f371ffa..0b298ab 100644
--- a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
+++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
@@ -67,11 +67,7 @@
void CPDF_PageContentGenerator::GenerateContent() {
ASSERT(m_pObjHolder->IsPage());
-
- std::map<int32_t, std::unique_ptr<std::ostringstream>> stream =
- GenerateModifiedStreams();
-
- UpdateContentStreams(&stream);
+ UpdateContentStreams(GenerateModifiedStreams());
}
std::map<int32_t, std::unique_ptr<std::ostringstream>>
@@ -144,14 +140,15 @@
}
void CPDF_PageContentGenerator::UpdateContentStreams(
- std::map<int32_t, std::unique_ptr<std::ostringstream>>* new_stream_data) {
+ const std::map<int32_t, std::unique_ptr<std::ostringstream>>&
+ new_stream_data) {
// If no streams were regenerated or removed, nothing to do here.
- if (new_stream_data->empty())
+ if (new_stream_data.empty())
return;
CPDF_PageContentManager page_content_manager(m_pObjHolder.Get());
- for (auto& pair : *new_stream_data) {
+ for (auto& pair : new_stream_data) {
int32_t stream_index = pair.first;
std::ostringstream* buf = pair.second.get();
diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator.h b/core/fpdfapi/edit/cpdf_pagecontentgenerator.h
index f1126f2..79bcdff 100644
--- a/core/fpdfapi/edit/cpdf_pagecontentgenerator.h
+++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator.h
@@ -60,7 +60,8 @@
// Add buffer as a stream in page's 'Contents'
void UpdateContentStreams(
- std::map<int32_t, std::unique_ptr<std::ostringstream>>* new_stream_data);
+ const std::map<int32_t, std::unique_ptr<std::ostringstream>>&
+ new_stream_data);
// Set the stream index of all page objects with stream index ==
// |CPDF_PageObject::kNoContentStream|. These are new objects that had not