From 2f2ffece124e4ed4b96d2846263015d4b5ad6c00 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Thu, 23 Jul 2015 14:42:09 -0700 Subject: Merge to XFA - else after returns. (cherry picked from commit 3c012fef2bb72c8ec1faa73e11ee35539b2559d6) Original Review URL: https://codereview.chromium.org/1243953004 . R=thestig@chromium.org Review URL: https://codereview.chromium.org/1239313005 . --- .../fpdfapi/fpdf_parser/fpdf_parser_objects.cpp | 89 +++++++++++----------- 1 file changed, 44 insertions(+), 45 deletions(-) (limited to 'core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp') diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp index 190cb2d0f1..8162fff297 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp @@ -160,8 +160,8 @@ CPDF_Array* CPDF_Object::GetArray() const { if (m_Type == PDFOBJ_ARRAY) return (CPDF_Array*)this; - else - return NULL; + + return NULL; } void CPDF_Object::SetString(const CFX_ByteString& str) { @@ -201,7 +201,8 @@ FX_BOOL CPDF_Object::IsIdentical(CPDF_Object* pOther) const if (pOther->m_Type != m_Type) { if (m_Type == PDFOBJ_REFERENCE && GetDirect()) { return GetDirect()->IsIdentical(pOther); - } else if (pOther->m_Type == PDFOBJ_REFERENCE) { + } + if (pOther->m_Type == PDFOBJ_REFERENCE) { return IsIdentical(pOther->GetDirect()); } return FALSE; @@ -285,27 +286,22 @@ CPDF_Object* CPDF_Object::CloneInternal(FX_BOOL bDirect, CFX_MapPtrToPtr* visite CPDF_StreamAcc acc; acc.LoadAllData(pThis, TRUE); FX_DWORD streamSize = acc.GetSize(); - CPDF_Stream* pObj; - if (pThis->GetDict()) - pObj = new CPDF_Stream(acc.DetachData(), streamSize, (CPDF_Dictionary*)((CPDF_Object*)pThis->GetDict())->CloneInternal(bDirect, visited)); - else - pObj = new CPDF_Stream(acc.DetachData(), streamSize, NULL); - return pObj; + CPDF_Dictionary* pDict = pThis->GetDict(); + if (pDict) + pDict = (CPDF_Dictionary*)((CPDF_Object*)pDict)->CloneInternal(bDirect, visited); + return new CPDF_Stream(acc.DetachData(), streamSize, pDict); } case PDFOBJ_REFERENCE: { CPDF_Reference* pRef = (CPDF_Reference*)this; FX_DWORD obj_num = pRef->m_RefObjNum; if (bDirect && !visited->GetValueAt((void*)(uintptr_t)obj_num)) { visited->SetAt((void*)(uintptr_t)obj_num, (void*)1); - CPDF_Object* ret; - if (pRef->GetDirect()) - ret = pRef->GetDirect()->CloneInternal(TRUE, visited); - else - ret = NULL; - return ret; - } else { - return new CPDF_Reference(pRef->m_pObjList, obj_num); + if (!pRef->GetDirect()) + return nullptr; + + return pRef->GetDirect()->CloneInternal(TRUE, visited); } + return new CPDF_Reference(pRef->m_pObjList, obj_num); } } return NULL; @@ -321,12 +317,14 @@ CFX_WideString CPDF_Object::GetUnicodeText(CFX_CharMap* pCharMap) const { if (m_Type == PDFOBJ_STRING) { return PDF_DecodeText(((CPDF_String*)this)->m_String, pCharMap); - } else if (m_Type == PDFOBJ_STREAM) { + } + if (m_Type == PDFOBJ_STREAM) { CPDF_StreamAcc stream; stream.LoadAllData((CPDF_Stream*)this, FALSE); CFX_WideString result = PDF_DecodeText(stream.GetData(), stream.GetSize(), pCharMap); return result; - } else if (m_Type == PDFOBJ_NAME) { + } + if (m_Type == PDFOBJ_NAME) { return PDF_DecodeText(((CPDF_Name*)this)->m_Name, pCharMap); } return CFX_WideString(); @@ -427,8 +425,7 @@ CFX_ByteString CPDF_Array::GetString(FX_DWORD i) const CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i); return p->GetString(); } - else - return CFX_ByteString(); + return CFX_ByteString(); } CFX_ByteStringC CPDF_Array::GetConstString(FX_DWORD i) const { @@ -436,8 +433,7 @@ CFX_ByteStringC CPDF_Array::GetConstString(FX_DWORD i) const CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i); return p->GetConstString(); } - else - return CFX_ByteStringC(); + return CFX_ByteStringC(); } int CPDF_Array::GetInteger(FX_DWORD i) const { @@ -458,11 +454,13 @@ FX_FLOAT CPDF_Array::GetNumber(FX_DWORD i) const CPDF_Dictionary* CPDF_Array::GetDict(FX_DWORD i) const { CPDF_Object* p = GetElementValue(i); - if (p == NULL) { + if (!p) { return NULL; - } else if (p->GetType() == PDFOBJ_DICTIONARY) { + } + if (p->GetType() == PDFOBJ_DICTIONARY) { return (CPDF_Dictionary*)p; - } else if (p->GetType() == PDFOBJ_STREAM) { + } + if (p->GetType() == PDFOBJ_STREAM) { return ((CPDF_Stream*)p)->GetDict(); } return NULL; @@ -604,19 +602,19 @@ CFX_ByteString CPDF_Dictionary::GetString(const CFX_ByteStringC& key) const { CPDF_Object* p = NULL; m_Map.Lookup(key, (void*&)p); - if (p) + if (p) { return p->GetString(); - else - return CFX_ByteString(); + } + return CFX_ByteString(); } CFX_ByteStringC CPDF_Dictionary::GetConstString(const CFX_ByteStringC& key) const { CPDF_Object* p = NULL; m_Map.Lookup(key, (void*&)p); - if (p) + if (p) { return p->GetConstString(); - else - return CFX_ByteStringC(); + } + return CFX_ByteStringC(); } CFX_WideString CPDF_Dictionary::GetUnicodeText(const CFX_ByteStringC& key, CFX_CharMap* pCharMap) const { @@ -647,10 +645,10 @@ CFX_ByteStringC CPDF_Dictionary::GetConstString(const CFX_ByteStringC& key, cons { CPDF_Object* p = NULL; m_Map.Lookup(key, (void*&)p); - if (p) + if (p) { return p->GetConstString(); - else - return CFX_ByteStringC(def); + } + return CFX_ByteStringC(def); } int CPDF_Dictionary::GetInteger(const CFX_ByteStringC& key) const { @@ -691,14 +689,16 @@ FX_BOOL CPDF_Dictionary::GetBoolean(const CFX_ByteStringC& key, FX_BOOL bDefault CPDF_Dictionary* CPDF_Dictionary::GetDict(const CFX_ByteStringC& key) const { CPDF_Object* p = GetElementValue(key); - if (p == NULL) { - return NULL; - } else if (p->GetType() == PDFOBJ_DICTIONARY) { + if (!p) { + return nullptr; + } + if (p->GetType() == PDFOBJ_DICTIONARY) { return (CPDF_Dictionary*)p; - } else if (p->GetType() == PDFOBJ_STREAM) { + } + if (p->GetType() == PDFOBJ_STREAM) { return ((CPDF_Stream*)p)->GetDict(); } - return NULL; + return nullptr; } CPDF_Array* CPDF_Dictionary::GetArray(const CFX_ByteStringC& key) const { @@ -1270,12 +1270,11 @@ void CPDF_IndirectObjects::InsertIndirectObject(FX_DWORD objnum, CPDF_Object* pO } void* value = NULL; if (m_IndirectObjs.Lookup((void*)(uintptr_t)objnum, value)) { - if (value) - { - if (pObj->GetGenNum() <= ((CPDF_Object*)value)->GetGenNum()) + if (value) { + if (pObj->GetGenNum() <= ((CPDF_Object*)value)->GetGenNum()) { return; - else - ((CPDF_Object*)value)->Destroy(); + } + ((CPDF_Object*)value)->Destroy(); } } pObj->m_ObjNum = objnum; -- cgit v1.2.3