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 --- fpdfsdk/formfiller/cba_fontmap.cpp | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) (limited to 'fpdfsdk/formfiller') diff --git a/fpdfsdk/formfiller/cba_fontmap.cpp b/fpdfsdk/formfiller/cba_fontmap.cpp index fe690f23d5..04d6a72ec5 100644 --- a/fpdfsdk/formfiller/cba_fontmap.cpp +++ b/fpdfsdk/formfiller/cba_fontmap.cpp @@ -154,7 +154,6 @@ void CBA_FontMap::AddFontToAnnotDict(CPDF_Font* pFont, return; CPDF_Dictionary* pAPDict = m_pAnnotDict->GetDictFor("AP"); - if (!pAPDict) { pAPDict = new CPDF_Dictionary; m_pAnnotDict->SetFor("AP", pAPDict); @@ -168,12 +167,11 @@ void CBA_FontMap::AddFontToAnnotDict(CPDF_Font* pFont, CPDF_Stream* pStream = pAPDict->GetStreamFor(m_sAPType); if (!pStream) { pStream = new CPDF_Stream; - int32_t objnum = m_pDocument->AddIndirectObject(pStream); - pAPDict->SetReferenceFor(m_sAPType, m_pDocument, objnum); + pAPDict->SetReferenceFor(m_sAPType, m_pDocument, + m_pDocument->AddIndirectObject(pStream)); } CPDF_Dictionary* pStreamDict = pStream->GetDict(); - if (!pStreamDict) { pStreamDict = new CPDF_Dictionary; pStream->InitStream(nullptr, 0, pStreamDict); @@ -185,17 +183,16 @@ void CBA_FontMap::AddFontToAnnotDict(CPDF_Font* pFont, pStreamResList = new CPDF_Dictionary(); pStreamDict->SetFor("Resources", pStreamResList); } - - if (pStreamResList) { - CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictFor("Font"); - if (!pStreamResFontList) { - pStreamResFontList = new CPDF_Dictionary; - int32_t objnum = m_pDocument->AddIndirectObject(pStreamResFontList); - pStreamResList->SetReferenceFor("Font", m_pDocument, objnum); - } - if (!pStreamResFontList->KeyExist(sAlias)) - pStreamResFontList->SetReferenceFor(sAlias, m_pDocument, - pFont->GetFontDict()); + CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictFor("Font"); + if (!pStreamResFontList) { + pStreamResFontList = new CPDF_Dictionary; + pStreamResList->SetReferenceFor( + "Font", m_pDocument, + m_pDocument->AddIndirectObject(pStreamResFontList)); + } + if (!pStreamResFontList->KeyExist(sAlias)) { + pStreamResFontList->SetReferenceFor(sAlias, m_pDocument, + pFont->GetFontDict()->GetObjNum()); } } } -- cgit v1.2.3