diff options
author | tsepez <tsepez@chromium.org> | 2016-11-16 17:31:18 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-11-16 17:31:18 -0800 |
commit | 5913a6ca71c85401e3f5317758d44a9fc4a667b2 (patch) | |
tree | 388ad0bd98b44a47c251568e198e2c3c231c7d30 /core/fpdfapi/parser/cpdf_indirect_object_holder.h | |
parent | cc4d0a44f3025821f88f3ed1ee78dfdc416487c7 (diff) | |
download | pdfium-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_indirect_object_holder.h')
-rw-r--r-- | core/fpdfapi/parser/cpdf_indirect_object_holder.h | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/core/fpdfapi/parser/cpdf_indirect_object_holder.h b/core/fpdfapi/parser/cpdf_indirect_object_holder.h index 375010de93..a78e6663b3 100644 --- a/core/fpdfapi/parser/cpdf_indirect_object_holder.h +++ b/core/fpdfapi/parser/cpdf_indirect_object_holder.h @@ -9,14 +9,14 @@ #include <map> #include <memory> +#include <type_traits> +#include "core/fpdfapi/parser/cpdf_object.h" #include "core/fxcrt/cfx_string_pool_template.h" #include "core/fxcrt/cfx_weak_ptr.h" #include "core/fxcrt/fx_system.h" #include "third_party/base/ptr_util.h" -class CPDF_Object; - class CPDF_IndirectObjectHolder { public: using const_iterator = @@ -30,11 +30,19 @@ class CPDF_IndirectObjectHolder { void DeleteIndirectObject(uint32_t objnum); // Creates and adds a new object owned by the indirect object holder, - // and returns an unowned pointer to it. + // and returns an unowned pointer to it. We have a special case to + // handle objects that can intern strings from our ByteStringPool. template <typename T, typename... Args> - T* NewIndirect(Args... args) { + typename std::enable_if<!CanInternStrings<T>::value, T*>::type NewIndirect( + Args... args) { return static_cast<T*>(AddIndirectObject(pdfium::MakeUnique<T>(args...))); } + template <typename T, typename... Args> + typename std::enable_if<CanInternStrings<T>::value, T*>::type NewIndirect( + Args... args) { + return static_cast<T*>( + AddIndirectObject(pdfium::MakeUnique<T>(m_pByteStringPool, args...))); + } // Takes ownership of |pObj|, returns unowned pointer to it. CPDF_Object* AddIndirectObject(std::unique_ptr<CPDF_Object> pObj); |