Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2406)

Unified Diff: core/fpdfapi/parser/cpdf_array.h

Issue 2509123002: Make CPDF_Object subclass constructors intern strings (Closed)
Patch Set: Nits Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « core/fpdfapi/parser/cfdf_document.cpp ('k') | core/fpdfapi/parser/cpdf_array.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/fpdfapi/parser/cpdf_array.h
diff --git a/core/fpdfapi/parser/cpdf_array.h b/core/fpdfapi/parser/cpdf_array.h
index b7aec7e190327dbf66cd206aaaa7fadd8f6252b8..125cb4cbf8c51cfaba89debb733575f9b15527d3 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) {
« no previous file with comments | « core/fpdfapi/parser/cfdf_document.cpp ('k') | core/fpdfapi/parser/cpdf_array.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698