From 59c1ac070d1c8ca70e96805b697c5635ccd70cdf Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Fri, 9 Jun 2017 11:04:41 -0700 Subject: Simplify CPDF_Array::RemoveAt(index, size). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of one general RemoveAt() method, split it into: - RemoveAt(index) - Truncate(nNewSize) - Clear() Update callers, which are now easier to understand. Update existing unit tests and add new tests. Change-Id: I38fe40146ce8f2479677b2caadd20a1756678768 Reviewed-on: https://pdfium-review.googlesource.com/6417 Commit-Queue: Lei Zhang Reviewed-by: Nicolás Peña --- fpdfsdk/fpdfannot.cpp | 6 +++--- fpdfsdk/fpdfeditpage.cpp | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'fpdfsdk') diff --git a/fpdfsdk/fpdfannot.cpp b/fpdfsdk/fpdfannot.cpp index 941a5fdd80..0c2152a7aa 100644 --- a/fpdfsdk/fpdfannot.cpp +++ b/fpdfsdk/fpdfannot.cpp @@ -184,7 +184,7 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFAnnot_SetColor(FPDF_ANNOTATION annot, CFX_ByteString key = type == FPDFANNOT_COLORTYPE_InteriorColor ? "IC" : "C"; CPDF_Array* pColor = pAnnotDict->GetArrayFor(key); if (pColor) - pColor->RemoveAt(0, pColor->GetCount()); + pColor->Clear(); else pColor = pAnnotDict->SetNewFor(key); @@ -270,7 +270,7 @@ FPDFAnnot_SetAttachmentPoints(FPDF_ANNOTATION annot, CPDF_Dictionary* pAnnotDict = CPDFDictionaryFromFPDFAnnotation(annot); CPDF_Array* pQuadPoints = pAnnotDict->GetArrayFor("QuadPoints"); if (pQuadPoints) - pQuadPoints->RemoveAt(0, pQuadPoints->GetCount()); + pQuadPoints->Clear(); else pQuadPoints = pAnnotDict->SetNewFor("QuadPoints"); @@ -315,7 +315,7 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFAnnot_SetRect(FPDF_ANNOTATION annot, CPDF_Array* pRect = pAnnotDict->GetArrayFor("Rect"); if (pRect) - pRect->RemoveAt(0, pRect->GetCount()); + pRect->Clear(); else pRect = pAnnotDict->SetNewFor("Rect"); diff --git a/fpdfsdk/fpdfeditpage.cpp b/fpdfsdk/fpdfeditpage.cpp index 22b2261c6f..699e030c49 100644 --- a/fpdfsdk/fpdfeditpage.cpp +++ b/fpdfsdk/fpdfeditpage.cpp @@ -297,11 +297,12 @@ DLLEXPORT void STDCALL FPDFPage_TransformAnnots(FPDF_PAGE page, (float)f); matrix.TransformRect(rect); - CPDF_Array* pRectArray = pAnnot->GetAnnotDict()->GetArrayFor("Rect"); + CPDF_Dictionary* pAnnotDict = pAnnot->GetAnnotDict(); + CPDF_Array* pRectArray = pAnnotDict->GetArrayFor("Rect"); if (pRectArray) - pRectArray->RemoveAt(0, pRectArray->GetCount()); + pRectArray->Clear(); else - pRectArray = pAnnot->GetAnnotDict()->SetNewFor("Rect"); + pRectArray = pAnnotDict->SetNewFor("Rect"); pRectArray->AddNew(rect.left); pRectArray->AddNew(rect.bottom); -- cgit v1.2.3