summaryrefslogtreecommitdiff
path: root/core/fpdfapi/parser/cpdf_array.h
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-11-16 17:31:18 -0800
committerCommit bot <commit-bot@chromium.org>2016-11-16 17:31:18 -0800
commit5913a6ca71c85401e3f5317758d44a9fc4a667b2 (patch)
tree388ad0bd98b44a47c251568e198e2c3c231c7d30 /core/fpdfapi/parser/cpdf_array.h
parentcc4d0a44f3025821f88f3ed1ee78dfdc416487c7 (diff)
downloadpdfium-5913a6ca71c85401e3f5317758d44a9fc4a667b2.tar.xz
Make CPDF_Object subclass constructors intern strings
Make CDPF_Arrays intern the object they create. Allow passing nullptr as a CFX_WeakPtr shortcut as well. Review-Url: https://codereview.chromium.org/2509123002
Diffstat (limited to 'core/fpdfapi/parser/cpdf_array.h')
-rw-r--r--core/fpdfapi/parser/cpdf_array.h35
1 files changed, 32 insertions, 3 deletions
diff --git a/core/fpdfapi/parser/cpdf_array.h b/core/fpdfapi/parser/cpdf_array.h
index b7aec7e190..125cb4cbf8 100644
--- a/core/fpdfapi/parser/cpdf_array.h
+++ b/core/fpdfapi/parser/cpdf_array.h
@@ -9,6 +9,7 @@
#include <memory>
#include <set>
+#include <type_traits>
#include <vector>
#include "core/fpdfapi/parser/cpdf_indirect_object_holder.h"
@@ -23,6 +24,7 @@ class CPDF_Array : public CPDF_Object {
std::vector<std::unique_ptr<CPDF_Object>>::const_iterator;
CPDF_Array();
+ explicit CPDF_Array(const CFX_WeakPtr<CFX_ByteStringPool>& pPool);
~CPDF_Array() override;
// CPDF_Object:
@@ -52,18 +54,44 @@ class CPDF_Array : public CPDF_Object {
CPDF_Object* InsertAt(size_t index, std::unique_ptr<CPDF_Object> pObj);
// Creates object owned by the array, returns unowned pointer to it.
+ // We have special cases for objects that can intern strings from
+ // a ByteStringPool.
template <typename T, typename... Args>
- T* AddNew(Args... args) {
+ typename std::enable_if<!CanInternStrings<T>::value, T*>::type AddNew(
+ Args... args) {
return static_cast<T*>(Add(pdfium::MakeUnique<T>(args...)));
}
template <typename T, typename... Args>
- T* SetNewAt(size_t index, Args... args) {
+ typename std::enable_if<CanInternStrings<T>::value, T*>::type AddNew(
+ Args... args) {
+ return static_cast<T*>(Add(pdfium::MakeUnique<T>(m_pPool, args...)));
+ }
+ template <typename T, typename... Args>
+ typename std::enable_if<!CanInternStrings<T>::value, T*>::type SetNewAt(
+ size_t index,
+ Args... args) {
return static_cast<T*>(SetAt(index, pdfium::MakeUnique<T>(args...)));
}
template <typename T, typename... Args>
- T* InsertNewAt(size_t index, Args... args) {
+ typename std::enable_if<CanInternStrings<T>::value, T*>::type SetNewAt(
+ size_t index,
+ Args... args) {
+ return static_cast<T*>(
+ SetAt(index, pdfium::MakeUnique<T>(m_pPool, args...)));
+ }
+ template <typename T, typename... Args>
+ typename std::enable_if<!CanInternStrings<T>::value, T*>::type InsertNewAt(
+ size_t index,
+ Args... args) {
return static_cast<T*>(InsertAt(index, pdfium::MakeUnique<T>(args...)));
}
+ template <typename T, typename... Args>
+ typename std::enable_if<CanInternStrings<T>::value, T*>::type InsertNewAt(
+ size_t index,
+ Args... args) {
+ return static_cast<T*>(
+ InsertAt(index, pdfium::MakeUnique<T>(m_pPool, args...)));
+ }
void RemoveAt(size_t index, size_t nCount = 1);
void ConvertToIndirectObjectAt(size_t index, CPDF_IndirectObjectHolder* pDoc);
@@ -77,6 +105,7 @@ class CPDF_Array : public CPDF_Object {
std::set<const CPDF_Object*>* pVisited) const override;
std::vector<std::unique_ptr<CPDF_Object>> m_Objects;
+ CFX_WeakPtr<CFX_ByteStringPool> m_pPool;
};
inline CPDF_Array* ToArray(CPDF_Object* obj) {