From bb577af2f17467a55c04fbff21a8f0ec1016601a Mon Sep 17 00:00:00 2001 From: tsepez Date: Wed, 21 Sep 2016 19:10:19 -0700 Subject: Remove some objnum locals with AddIndirectObject Also, it's idempotent, so simplify some logic in callers to not care if objnum is zero. The alternate forms are rarely used, using the objnum form makes it clear that SetReferenceFor() can't possibly register the object as a side-effect. Review-Url: https://codereview.chromium.org/2361713002 --- core/fpdfapi/fpdf_page/cpdf_image.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'core/fpdfapi/fpdf_page') diff --git a/core/fpdfapi/fpdf_page/cpdf_image.cpp b/core/fpdfapi/fpdf_page/cpdf_image.cpp index 32b69bf9cb..4112ad86ee 100644 --- a/core/fpdfapi/fpdf_page/cpdf_image.cpp +++ b/core/fpdfapi/fpdf_page/cpdf_image.cpp @@ -201,7 +201,6 @@ void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap, int32_t iCompress) { int32_t iPalette = pBitmap->GetPaletteSize(); if (iPalette > 0) { CPDF_Array* pCS = new CPDF_Array; - m_pDocument->AddIndirectObject(pCS); pCS->AddName("Indexed"); pCS->AddName("DeviceRGB"); pCS->AddInteger(iPalette - 1); @@ -216,9 +215,9 @@ void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap, int32_t iCompress) { } CPDF_Stream* pCTS = new CPDF_Stream(pColorTable, iPalette * 3, new CPDF_Dictionary); - m_pDocument->AddIndirectObject(pCTS); - pCS->AddReference(m_pDocument, pCTS); - pDict->SetReferenceFor("ColorSpace", m_pDocument, pCS); + pCS->AddReference(m_pDocument, m_pDocument->AddIndirectObject(pCTS)); + pDict->SetReferenceFor("ColorSpace", m_pDocument, + m_pDocument->AddIndirectObject(pCS)); } else { pDict->SetNameFor("ColorSpace", "DeviceGray"); } @@ -269,13 +268,11 @@ void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap, int32_t iCompress) { } } pMaskDict->SetIntegerFor("Length", mask_size); - - CPDF_Stream* pMaskStream = new CPDF_Stream(mask_buf, mask_size, pMaskDict); - m_pDocument->AddIndirectObject(pMaskStream); - pDict->SetReferenceFor("SMask", m_pDocument, pMaskStream); - if (bDeleteMask) { + pDict->SetReferenceFor("SMask", m_pDocument, + m_pDocument->AddIndirectObject(new CPDF_Stream( + mask_buf, mask_size, pMaskDict))); + if (bDeleteMask) delete pMaskBitmap; - } } if (opType == 0) { if (iCompress & PDF_IMAGE_LOSSLESS_COMPRESS) { -- cgit v1.2.3