summaryrefslogtreecommitdiff
path: root/core/fpdfapi/page/cpdf_contentmark.cpp
diff options
context:
space:
mode:
authorHenrique Nakashima <hnakashima@chromium.org>2018-07-05 15:39:59 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-07-05 15:39:59 +0000
commit86b4f67d40c351ea8e67ba7b7dcc9d8dd7ad371e (patch)
tree54881ef1ca024cd369862cff584b5fd434c1a183 /core/fpdfapi/page/cpdf_contentmark.cpp
parentd774a73b59ac36d533064041196d051c032eee6b (diff)
downloadpdfium-86b4f67d40c351ea8e67ba7b7dcc9d8dd7ad371e.tar.xz
Replace SharedCopyOnWrite<MarkData> with RetainPtr
A RetainPtr is already used inside SharedCopyOnWrite, and the API that CPDF_ContentMark offers is not intuitive. AddMark() and RemoveLastMark() currently copy the MarkData. The new API does not perform these copies, but rather leaves it to the client code. This is the first step to make CPDF_ContentMarkItems modifiable. As long as they are inside a SharedCopyOnWrite, they cannot be changed. Bug: pdfium:1037 Change-Id: I0cd6334b0b8db62070b4412f1d6d1c88bce9891f Reviewed-on: https://pdfium-review.googlesource.com/37132 Reviewed-by: Ryan Harrison <rharrison@chromium.org> Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'core/fpdfapi/page/cpdf_contentmark.cpp')
-rw-r--r--core/fpdfapi/page/cpdf_contentmark.cpp33
1 files changed, 23 insertions, 10 deletions
diff --git a/core/fpdfapi/page/cpdf_contentmark.cpp b/core/fpdfapi/page/cpdf_contentmark.cpp
index deddf3cc3e..77c29a53d7 100644
--- a/core/fpdfapi/page/cpdf_contentmark.cpp
+++ b/core/fpdfapi/page/cpdf_contentmark.cpp
@@ -12,35 +12,48 @@
CPDF_ContentMark::CPDF_ContentMark() {}
-CPDF_ContentMark::CPDF_ContentMark(const CPDF_ContentMark& that)
- : m_Ref(that.m_Ref) {}
-
CPDF_ContentMark::~CPDF_ContentMark() {}
+std::unique_ptr<CPDF_ContentMark> CPDF_ContentMark::Clone() {
+ auto result = pdfium::MakeUnique<CPDF_ContentMark>();
+ if (m_Ref)
+ result->m_Ref.Reset(new MarkData(*m_Ref));
+
+ return result;
+}
+
size_t CPDF_ContentMark::CountItems() const {
- return m_Ref.GetObject()->CountItems();
+ return m_Ref->CountItems();
}
const CPDF_ContentMarkItem& CPDF_ContentMark::GetItem(size_t i) const {
ASSERT(i < CountItems());
- return m_Ref.GetObject()->GetItem(i);
+ return m_Ref->GetItem(i);
}
int CPDF_ContentMark::GetMarkedContentID() const {
- const MarkData* pData = m_Ref.GetObject();
- return pData ? pData->GetMarkedContentID() : -1;
+ if (!m_Ref)
+ return -1;
+
+ return m_Ref->GetMarkedContentID();
}
void CPDF_ContentMark::AddMark(ByteString name,
const CPDF_Dictionary* pDict,
bool bDirect) {
- m_Ref.GetPrivateCopy()->AddMark(std::move(name), pDict, bDirect);
+ if (!m_Ref)
+ m_Ref.Reset(new MarkData());
+
+ m_Ref->AddMark(std::move(name), pDict, bDirect);
}
void CPDF_ContentMark::DeleteLastMark() {
- m_Ref.GetPrivateCopy()->DeleteLastMark();
+ if (!m_Ref)
+ return;
+
+ m_Ref->DeleteLastMark();
if (CountItems() == 0)
- m_Ref.SetNull();
+ m_Ref.Reset();
}
CPDF_ContentMark::MarkData::MarkData() {}