From df964dfb34e648e27dce7bef785b204894a7058a Mon Sep 17 00:00:00 2001 From: tsepez Date: Thu, 21 Apr 2016 12:09:41 -0700 Subject: Replace CFX_RectArray with std::vector Use RVO now that we use an array type compatible with it. Review URL: https://codereview.chromium.org/1906903002 --- fpdfsdk/fpdftext.cpp | 19 ++++++++----------- fpdfsdk/fsdk_mgr.cpp | 8 +++----- fpdfsdk/include/fsdk_mgr.h | 2 +- fpdfsdk/javascript/Document.cpp | 4 +--- 4 files changed, 13 insertions(+), 20 deletions(-) (limited to 'fpdfsdk') diff --git a/fpdfsdk/fpdftext.cpp b/fpdfsdk/fpdftext.cpp index 2a84131422..4d521da8ed 100644 --- a/fpdfsdk/fpdftext.cpp +++ b/fpdfsdk/fpdftext.cpp @@ -13,6 +13,7 @@ #include "core/fpdftext/include/cpdf_textpagefind.h" #include "fpdfsdk/include/fsdk_define.h" #include "third_party/base/numerics/safe_conversions.h" +#include "third_party/base/stl_util.h" #ifdef PDF_ENABLE_XFA #include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h" @@ -315,10 +316,8 @@ DLLEXPORT int STDCALL FPDFLink_CountRects(FPDF_PAGELINK link_page, if (!link_page || link_index < 0) return 0; - CFX_RectArray rects; CPDF_LinkExtract* pageLink = CPDFLinkExtractFromFPDFPageLink(link_page); - pageLink->GetRects(link_index, &rects); - return rects.GetSize(); + return pdfium::CollectionSize(pageLink->GetRects(link_index)); } DLLEXPORT void STDCALL FPDFLink_GetRect(FPDF_PAGELINK link_page, @@ -331,17 +330,15 @@ DLLEXPORT void STDCALL FPDFLink_GetRect(FPDF_PAGELINK link_page, if (!link_page || link_index < 0 || rect_index < 0) return; - CFX_RectArray rectArray; CPDF_LinkExtract* pageLink = CPDFLinkExtractFromFPDFPageLink(link_page); - pageLink->GetRects(link_index, &rectArray); - if (rect_index >= rectArray.GetSize()) + std::vector rectArray = pageLink->GetRects(link_index); + if (rect_index >= pdfium::CollectionSize(rectArray)) return; - CFX_FloatRect rect = rectArray.GetAt(rect_index); - *left = rect.left; - *right = rect.right; - *top = rect.top; - *bottom = rect.bottom; + *left = rectArray[rect_index].left; + *right = rectArray[rect_index].right; + *top = rectArray[rect_index].top; + *bottom = rectArray[rect_index].bottom; } DLLEXPORT void STDCALL FPDFLink_CloseWebLinks(FPDF_PAGELINK link_page) { diff --git a/fpdfsdk/fsdk_mgr.cpp b/fpdfsdk/fsdk_mgr.cpp index 7240fe1d0b..cfb1b8a8b3 100644 --- a/fpdfsdk/fsdk_mgr.cpp +++ b/fpdfsdk/fsdk_mgr.cpp @@ -1158,12 +1158,10 @@ void CPDFSDK_PageView::ClearFXAnnots() { SetLock(FALSE); } -void CPDFSDK_PageView::UpdateRects(CFX_RectArray& rects) { - for (int i = 0; i < rects.GetSize(); i++) { - CFX_FloatRect rc = rects.GetAt(i); - CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); +void CPDFSDK_PageView::UpdateRects(const std::vector& rects) { + CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); + for (const auto& rc : rects) pEnv->FFI_Invalidate(m_page, rc.left, rc.top, rc.right, rc.bottom); - } } void CPDFSDK_PageView::UpdateView(CPDFSDK_Annot* pAnnot) { diff --git a/fpdfsdk/include/fsdk_mgr.h b/fpdfsdk/include/fsdk_mgr.h index 3d691c1f2d..0578a16e3d 100644 --- a/fpdfsdk/include/fsdk_mgr.h +++ b/fpdfsdk/include/fsdk_mgr.h @@ -614,7 +614,7 @@ class CPDFSDK_PageView final { int nFlag); bool IsValidAnnot(const CPDF_Annot* p) const; void GetCurrentMatrix(CFX_Matrix& matrix) { matrix = m_curMatrix; } - void UpdateRects(CFX_RectArray& rects); + void UpdateRects(const std::vector& rects); void UpdateView(CPDFSDK_Annot* pAnnot); const std::vector& GetAnnotList() const { return m_fxAnnotArray; diff --git a/fpdfsdk/javascript/Document.cpp b/fpdfsdk/javascript/Document.cpp index 551d649830..fa2f7ae4e4 100644 --- a/fpdfsdk/javascript/Document.cpp +++ b/fpdfsdk/javascript/Document.cpp @@ -494,9 +494,7 @@ FX_BOOL Document::removeField(IJS_Context* cc, ++rcAnnot.right; ++rcAnnot.top; - CFX_RectArray aRefresh; - aRefresh.Add(rcAnnot); - + std::vector aRefresh(1, rcAnnot); UnderlyingPageType* pPage = pWidget->GetUnderlyingPage(); ASSERT(pPage); -- cgit v1.2.3