From 7b1ccf9697692844e764d730079a0f0b98fd6d06 Mon Sep 17 00:00:00 2001 From: tsepez Date: Thu, 14 Apr 2016 11:04:57 -0700 Subject: Make CPDF_Dictionary methods take CFX_ByteString arguments This will help avoid duplicate allocation of CFX_ByteStrings when the caller already has one. It may seem counter-intuitive that requiring the caller to pass an allocated CFX_ByteString rather than a static CFX_ByteStringC would improve the situation, but due to the idiosyncrasies of std::map, the CPDF_Dictionary methods must always do an allocation under the covers which can't be avoided. The changed callers in this CL are places where we would previously demote to CFX_ByteStringC and then allocate a a duplicate CFX_ByteString in the dictionary method. Review URL: https://codereview.chromium.org/1889863002 --- core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h | 60 +++++++++++----------- 1 file changed, 30 insertions(+), 30 deletions(-) (limited to 'core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h') diff --git a/core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h b/core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h index c39370e6ec..e3b7496da7 100644 --- a/core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h +++ b/core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h @@ -31,56 +31,56 @@ class CPDF_Dictionary : public CPDF_Object { const CPDF_Dictionary* AsDictionary() const override; size_t GetCount() const { return m_Map.size(); } - CPDF_Object* GetObjectBy(const CFX_ByteStringC& key) const; - CPDF_Object* GetDirectObjectBy(const CFX_ByteStringC& key) const; - CFX_ByteString GetStringBy(const CFX_ByteStringC& key) const; - CFX_ByteString GetStringBy(const CFX_ByteStringC& key, - const CFX_ByteStringC& default_str) const; - CFX_WideString GetUnicodeTextBy(const CFX_ByteStringC& key) const; - int GetIntegerBy(const CFX_ByteStringC& key) const; - int GetIntegerBy(const CFX_ByteStringC& key, int default_int) const; - FX_BOOL GetBooleanBy(const CFX_ByteStringC& key, + CPDF_Object* GetObjectBy(const CFX_ByteString& key) const; + CPDF_Object* GetDirectObjectBy(const CFX_ByteString& key) const; + CFX_ByteString GetStringBy(const CFX_ByteString& key) const; + CFX_ByteString GetStringBy(const CFX_ByteString& key, + const CFX_ByteString& default_str) const; + CFX_WideString GetUnicodeTextBy(const CFX_ByteString& key) const; + int GetIntegerBy(const CFX_ByteString& key) const; + int GetIntegerBy(const CFX_ByteString& key, int default_int) const; + FX_BOOL GetBooleanBy(const CFX_ByteString& key, FX_BOOL bDefault = FALSE) const; - FX_FLOAT GetNumberBy(const CFX_ByteStringC& key) const; - CPDF_Dictionary* GetDictBy(const CFX_ByteStringC& key) const; - CPDF_Stream* GetStreamBy(const CFX_ByteStringC& key) const; - CPDF_Array* GetArrayBy(const CFX_ByteStringC& key) const; - CFX_FloatRect GetRectBy(const CFX_ByteStringC& key) const; - CFX_Matrix GetMatrixBy(const CFX_ByteStringC& key) const; - FX_FLOAT GetFloatBy(const CFX_ByteStringC& key) const { + FX_FLOAT GetNumberBy(const CFX_ByteString& key) const; + CPDF_Dictionary* GetDictBy(const CFX_ByteString& key) const; + CPDF_Stream* GetStreamBy(const CFX_ByteString& key) const; + CPDF_Array* GetArrayBy(const CFX_ByteString& key) const; + CFX_FloatRect GetRectBy(const CFX_ByteString& key) const; + CFX_Matrix GetMatrixBy(const CFX_ByteString& key) const; + FX_FLOAT GetFloatBy(const CFX_ByteString& key) const { return GetNumberBy(key); } - FX_BOOL KeyExist(const CFX_ByteStringC& key) const; + FX_BOOL KeyExist(const CFX_ByteString& key) const; bool IsSignatureDict() const; // Set* functions invalidate iterators for the element with the key |key|. - void SetAt(const CFX_ByteStringC& key, CPDF_Object* pObj); - void SetAtName(const CFX_ByteStringC& key, const CFX_ByteString& name); - void SetAtString(const CFX_ByteStringC& key, const CFX_ByteString& str); - void SetAtInteger(const CFX_ByteStringC& key, int i); - void SetAtNumber(const CFX_ByteStringC& key, FX_FLOAT f); - void SetAtReference(const CFX_ByteStringC& key, + void SetAt(const CFX_ByteString& key, CPDF_Object* pObj); + void SetAtName(const CFX_ByteString& key, const CFX_ByteString& name); + void SetAtString(const CFX_ByteString& key, const CFX_ByteString& str); + void SetAtInteger(const CFX_ByteString& key, int i); + void SetAtNumber(const CFX_ByteString& key, FX_FLOAT f); + void SetAtReference(const CFX_ByteString& key, CPDF_IndirectObjectHolder* pDoc, uint32_t objnum); - void SetAtReference(const CFX_ByteStringC& key, + void SetAtReference(const CFX_ByteString& key, CPDF_IndirectObjectHolder* pDoc, CPDF_Object* obj) { SetAtReference(key, pDoc, obj->GetObjNum()); } - void SetAtRect(const CFX_ByteStringC& key, const CFX_FloatRect& rect); - void SetAtMatrix(const CFX_ByteStringC& key, const CFX_Matrix& matrix); - void SetAtBoolean(const CFX_ByteStringC& key, FX_BOOL bValue); + void SetAtRect(const CFX_ByteString& key, const CFX_FloatRect& rect); + void SetAtMatrix(const CFX_ByteString& key, const CFX_Matrix& matrix); + void SetAtBoolean(const CFX_ByteString& key, FX_BOOL bValue); - void AddReference(const CFX_ByteStringC& key, + void AddReference(const CFX_ByteString& key, CPDF_IndirectObjectHolder* pDoc, uint32_t objnum); // Invalidates iterators for the element with the key |key|. - void RemoveAt(const CFX_ByteStringC& key); + void RemoveAt(const CFX_ByteString& key); // Invalidates iterators for the element with the key |oldkey|. - void ReplaceKey(const CFX_ByteStringC& oldkey, const CFX_ByteStringC& newkey); + void ReplaceKey(const CFX_ByteString& oldkey, const CFX_ByteString& newkey); iterator begin() { return m_Map.begin(); } iterator end() { return m_Map.end(); } -- cgit v1.2.3