diff options
Diffstat (limited to 'core/fpdfapi')
-rw-r--r-- | core/fpdfapi/parser/cpdf_object_walker.cpp | 8 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_object_walker.h | 15 |
2 files changed, 12 insertions, 11 deletions
diff --git a/core/fpdfapi/parser/cpdf_object_walker.cpp b/core/fpdfapi/parser/cpdf_object_walker.cpp index 3aaa25e9f7..8424c0fc89 100644 --- a/core/fpdfapi/parser/cpdf_object_walker.cpp +++ b/core/fpdfapi/parser/cpdf_object_walker.cpp @@ -124,19 +124,19 @@ CPDF_ObjectWalker::MakeIterator(const CPDF_Object* object) { } CPDF_ObjectWalker::CPDF_ObjectWalker(const CPDF_Object* root) - : next_object_(root), parent_object_(nullptr), current_depth_(0) {} + : next_object_(root) {} -CPDF_ObjectWalker::~CPDF_ObjectWalker() {} +CPDF_ObjectWalker::~CPDF_ObjectWalker() = default; const CPDF_Object* CPDF_ObjectWalker::GetNext() { while (!stack_.empty() || next_object_) { if (next_object_) { - auto new_iterator = MakeIterator(next_object_); + auto new_iterator = MakeIterator(next_object_.Get()); if (new_iterator) { // Schedule walk within composite objects. stack_.push(std::move(new_iterator)); } - auto* result = next_object_; + auto* result = next_object_.Get(); next_object_ = nullptr; return result; } diff --git a/core/fpdfapi/parser/cpdf_object_walker.h b/core/fpdfapi/parser/cpdf_object_walker.h index d677712c9b..57506b9545 100644 --- a/core/fpdfapi/parser/cpdf_object_walker.h +++ b/core/fpdfapi/parser/cpdf_object_walker.h @@ -9,6 +9,7 @@ #include <stack> #include "core/fpdfapi/parser/cpdf_dictionary.h" +#include "core/fxcrt/unowned_ptr.h" // Walk on all non-null sub-objects in an object in depth, include itself, // like in flat list. @@ -17,10 +18,10 @@ class CPDF_ObjectWalker { class SubobjectIterator { public: virtual ~SubobjectIterator(); + virtual bool IsFinished() const = 0; bool IsStarted() const { return is_started_; } - bool virtual IsFinished() const = 0; const CPDF_Object* Increment(); - const CPDF_Object* object() const { return object_; } + const CPDF_Object* object() const { return object_.Get(); } protected: explicit SubobjectIterator(const CPDF_Object* object); @@ -29,7 +30,7 @@ class CPDF_ObjectWalker { virtual void Start() = 0; private: - const CPDF_Object* object_; + UnownedPtr<const CPDF_Object> object_; bool is_started_ = false; }; @@ -40,17 +41,17 @@ class CPDF_ObjectWalker { void SkipWalkIntoCurrentObject(); size_t current_depth() const { return current_depth_; } - const CPDF_Object* GetParent() const { return parent_object_; } + const CPDF_Object* GetParent() const { return parent_object_.Get(); } ByteString dictionary_key() const { return dict_key_; } private: static std::unique_ptr<SubobjectIterator> MakeIterator( const CPDF_Object* object); - const CPDF_Object* next_object_; - const CPDF_Object* parent_object_; + UnownedPtr<const CPDF_Object> next_object_; + UnownedPtr<const CPDF_Object> parent_object_; ByteString dict_key_; - size_t current_depth_; + size_t current_depth_ = 0; std::stack<std::unique_ptr<SubobjectIterator>> stack_; }; |