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

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

Issue 2509123002: Make CPDF_Object subclass constructors intern strings (Closed)
Patch Set: 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
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..9c3193325c08e7ab07e44ab5397fe07c3faaae4d 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"
@@ -52,18 +53,41 @@ 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<!std::is_same<T, CPDF_Name>::value, T*>::type AddNew(
Tom Sepez 2016/11/16 22:35:47 note: the return value type is nonsense if T is CP
+ 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<std::is_same<T, CPDF_Name>::value, T*>::type AddNew(
Tom Sepez 2016/11/16 22:35:47 Exact opposite. Inject a nullptr argument for the
+ Args... args) {
+ return static_cast<T*>(Add(pdfium::MakeUnique<T>(nullptr, args...)));
+ }
+ template <typename T, typename... Args>
+ typename std::enable_if<!std::is_same<T, CPDF_Name>::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<std::is_same<T, CPDF_Name>::value, T*>::type SetNewAt(
+ size_t index,
+ Args... args) {
+ return static_cast<T*>(
+ SetAt(index, pdfium::MakeUnique<T>(nullptr, args...)));
+ }
+ template <typename T, typename... Args>
+ typename std::enable_if<!std::is_same<T, CPDF_Name>::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<std::is_same<T, CPDF_Name>::value, T*>::type
+ InsertNewAt(size_t index, Args... args) {
+ return static_cast<T*>(
+ InsertAt(index, pdfium::MakeUnique<T>(nullptr, args...)));
+ }
void RemoveAt(size_t index, size_t nCount = 1);
void ConvertToIndirectObjectAt(size_t index, CPDF_IndirectObjectHolder* pDoc);

Powered by Google App Engine
This is Rietveld 408576698