From 51d02b341dd56f8e365444cb9e4af7e0ffe55ae5 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Mon, 30 Jan 2017 14:49:24 -0800 Subject: use std::vector in cfx_graphics.h and xfa_ffwidget.h Change-Id: I19f2e729b58de42506e8fc2811dd06d406470314 Reviewed-on: https://pdfium-review.googlesource.com/2470 Commit-Queue: dsinclair Reviewed-by: dsinclair --- xfa/fxfa/app/xfa_ffdocview.cpp | 11 ++++++----- xfa/fxfa/app/xfa_ffwidget.cpp | 4 +--- xfa/fxfa/app/xfa_ffwidgetacc.cpp | 5 ++--- xfa/fxfa/xfa_ffwidget.h | 2 +- xfa/fxgraphics/cfx_graphics.cpp | 37 ++++++++++++++++--------------------- xfa/fxgraphics/cfx_graphics.h | 3 ++- 6 files changed, 28 insertions(+), 34 deletions(-) diff --git a/xfa/fxfa/app/xfa_ffdocview.cpp b/xfa/fxfa/app/xfa_ffdocview.cpp index bf91baf082..0aedeed231 100644 --- a/xfa/fxfa/app/xfa_ffdocview.cpp +++ b/xfa/fxfa/app/xfa_ffdocview.cpp @@ -636,11 +636,12 @@ void CXFA_FFDocView::AddCalculateWidgetAcc(CXFA_WidgetAcc* pWidgetAcc) { } void CXFA_FFDocView::AddCalculateNodeNotify(CXFA_Node* pNodeChange) { - CXFA_CalcData* pGlobalData = - (CXFA_CalcData*)pNodeChange->GetUserData(XFA_CalcData); - int32_t iCount = pGlobalData ? pGlobalData->m_Globals.GetSize() : 0; - for (int32_t i = 0; i < iCount; i++) { - CXFA_WidgetAcc* pResultAcc = pGlobalData->m_Globals[i]; + auto pGlobalData = + static_cast(pNodeChange->GetUserData(XFA_CalcData)); + if (!pGlobalData) + return; + + for (const auto& pResultAcc : pGlobalData->m_Globals) { if (!pResultAcc->GetNode()->HasRemovedChildren()) AddCalculateWidgetAcc(pResultAcc); } diff --git a/xfa/fxfa/app/xfa_ffwidget.cpp b/xfa/fxfa/app/xfa_ffwidget.cpp index c1822470e0..4cd6b44a66 100644 --- a/xfa/fxfa/app/xfa_ffwidget.cpp +++ b/xfa/fxfa/app/xfa_ffwidget.cpp @@ -2048,6 +2048,4 @@ void XFA_DrawBox(CXFA_Box box, CXFA_CalcData::CXFA_CalcData() : m_iRefCount(0) {} -CXFA_CalcData::~CXFA_CalcData() { - m_Globals.RemoveAll(); -} +CXFA_CalcData::~CXFA_CalcData() {} diff --git a/xfa/fxfa/app/xfa_ffwidgetacc.cpp b/xfa/fxfa/app/xfa_ffwidgetacc.cpp index d4d9949c3e..5fe591c02a 100644 --- a/xfa/fxfa/app/xfa_ffwidgetacc.cpp +++ b/xfa/fxfa/app/xfa_ffwidgetacc.cpp @@ -678,9 +678,8 @@ int32_t CXFA_WidgetAcc::ExecuteScript(CXFA_Script script, pRefNode->SetUserData(XFA_CalcData, pGlobalData, &gs_XFADeleteCalcData); } - if (pGlobalData->m_Globals.Find(this) < 0) { - pGlobalData->m_Globals.Add(this); - } + if (!pdfium::ContainsValue(pGlobalData->m_Globals, this)) + pGlobalData->m_Globals.push_back(this); } } } diff --git a/xfa/fxfa/xfa_ffwidget.h b/xfa/fxfa/xfa_ffwidget.h index f4ef8ce97b..009cd44dc0 100644 --- a/xfa/fxfa/xfa_ffwidget.h +++ b/xfa/fxfa/xfa_ffwidget.h @@ -37,7 +37,7 @@ class CXFA_CalcData { CXFA_CalcData(); ~CXFA_CalcData(); - CFX_ArrayTemplate m_Globals; + std::vector m_Globals; int32_t m_iRefCount; }; diff --git a/xfa/fxgraphics/cfx_graphics.cpp b/xfa/fxgraphics/cfx_graphics.cpp index 059872f81c..120634ca51 100644 --- a/xfa/fxgraphics/cfx_graphics.cpp +++ b/xfa/fxgraphics/cfx_graphics.cpp @@ -630,30 +630,25 @@ FWL_Error CFX_Graphics::EnableAntialiasing(bool isAntialiasing) { } FWL_Error CFX_Graphics::SaveGraphState() { - if (m_type == FX_CONTEXT_Device && m_renderDevice) { - m_renderDevice->SaveState(); - m_infoStack.Add(new TInfo(m_info)); - return FWL_Error::Succeeded; - } - return FWL_Error::PropertyInvalid; + if (m_type != FX_CONTEXT_Device || !m_renderDevice) + return FWL_Error::PropertyInvalid; + + m_renderDevice->SaveState(); + m_infoStack.push_back(pdfium::MakeUnique(m_info)); + return FWL_Error::Succeeded; } FWL_Error CFX_Graphics::RestoreGraphState() { - if (m_type == FX_CONTEXT_Device && m_renderDevice) { - m_renderDevice->RestoreState(false); - int32_t size = m_infoStack.GetSize(); - if (size <= 0) { - return FWL_Error::IntermediateValueInvalid; - } - int32_t topIndex = size - 1; - std::unique_ptr info(m_infoStack.GetAt(topIndex)); - if (!info) - return FWL_Error::IntermediateValueInvalid; - m_info = *info; - m_infoStack.RemoveAt(topIndex); - return FWL_Error::Succeeded; - } - return FWL_Error::PropertyInvalid; + if (m_type != FX_CONTEXT_Device || !m_renderDevice) + return FWL_Error::PropertyInvalid; + + m_renderDevice->RestoreState(false); + if (m_infoStack.empty() || !m_infoStack.back()) + return FWL_Error::IntermediateValueInvalid; + + m_info = *m_infoStack.back(); + m_infoStack.pop_back(); + return FWL_Error::Succeeded; } FWL_Error CFX_Graphics::GetLineCap(CFX_GraphStateData::LineCap& lineCap) const { diff --git a/xfa/fxgraphics/cfx_graphics.h b/xfa/fxgraphics/cfx_graphics.h index e18564bf6d..48784254b0 100644 --- a/xfa/fxgraphics/cfx_graphics.h +++ b/xfa/fxgraphics/cfx_graphics.h @@ -8,6 +8,7 @@ #define XFA_FXGRAPHICS_CFX_GRAPHICS_H_ #include +#include #include "core/fxcrt/fx_system.h" #include "core/fxge/cfx_fxgedevice.h" @@ -233,7 +234,7 @@ class CFX_Graphics { CFX_RectF& rect); CFX_RenderDevice* m_renderDevice; - CFX_ArrayTemplate m_infoStack; + std::vector> m_infoStack; std::unique_ptr m_aggGraphics; friend class CAGG_Graphics; }; -- cgit v1.2.3