From 56c1019e694ba9c2d6624d3c11d99c22798ffdc8 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Tue, 15 Mar 2016 12:34:17 -0700 Subject: Remove CFX_DWordArray from Document.h Using a list is more appropriate, since we wish to delete from the middle. R=dsinclair@chromium.org Review URL: https://codereview.chromium.org/1780093003 . --- fpdfsdk/javascript/Document.cpp | 62 +++++++++++------------------------------ fpdfsdk/javascript/Document.h | 2 +- 2 files changed, 17 insertions(+), 47 deletions(-) diff --git a/fpdfsdk/javascript/Document.cpp b/fpdfsdk/javascript/Document.cpp index 241e03818e..5f6291b35a 100644 --- a/fpdfsdk/javascript/Document.cpp +++ b/fpdfsdk/javascript/Document.cpp @@ -158,11 +158,6 @@ Document::Document(CJS_Object* pJSObject) m_bDelay(FALSE) {} Document::~Document() { - for (int i = 0; i < m_DelayData.GetSize(); i++) { - delete m_DelayData.GetAt(i); - } - - m_DelayData.RemoveAll(); } // the total number of fileds in document. @@ -865,25 +860,12 @@ FX_BOOL Document::delay(IJS_Context* cc, vp >> m_bDelay; if (m_bDelay) { - for (int i = 0, sz = m_DelayData.GetSize(); i < sz; i++) - delete m_DelayData.GetAt(i); - - m_DelayData.RemoveAll(); + m_DelayData.clear(); } else { - CFX_ArrayTemplate DelayDataToProcess; - for (int i = 0, sz = m_DelayData.GetSize(); i < sz; i++) { - if (CJS_DelayData* pData = m_DelayData.GetAt(i)) { - DelayDataToProcess.Add(pData); - m_DelayData.SetAt(i, NULL); - } - } - m_DelayData.RemoveAll(); - for (int i = 0, sz = DelayDataToProcess.GetSize(); i < sz; i++) { - CJS_DelayData* pData = DelayDataToProcess.GetAt(i); - Field::DoDelay(m_pDocument, pData); - DelayDataToProcess.SetAt(i, NULL); - delete pData; - } + std::list> DelayDataToProcess; + DelayDataToProcess.swap(m_DelayData); + for (const auto& pData : DelayDataToProcess) + Field::DoDelay(m_pDocument, pData.get()); } } return TRUE; @@ -1597,36 +1579,24 @@ FX_BOOL Document::getURL(IJS_Context* cc, } void Document::AddDelayData(CJS_DelayData* pData) { - m_DelayData.Add(pData); + m_DelayData.push_back(std::unique_ptr(pData)); } void Document::DoFieldDelay(const CFX_WideString& sFieldName, int nControlIndex) { - CFX_DWordArray DelArray; - CFX_ArrayTemplate DelayDataForFieldAndControlIndex; - - for (int i = 0, sz = m_DelayData.GetSize(); i < sz; i++) { - if (CJS_DelayData* pData = m_DelayData.GetAt(i)) { - if (pData->sFieldName == sFieldName && - pData->nControlIndex == nControlIndex) { - DelayDataForFieldAndControlIndex.Add(pData); - m_DelayData.SetAt(i, NULL); - DelArray.Add(i); - } + std::vector> DelayDataForFieldAndControlIndex; + auto iter = m_DelayData.begin(); + while (iter != m_DelayData.end()) { + auto old = iter++; + if ((*old)->sFieldName == sFieldName && + (*old)->nControlIndex == nControlIndex) { + DelayDataForFieldAndControlIndex.push_back(std::move(*old)); + m_DelayData.erase(old); } } - for (int j = DelArray.GetSize() - 1; j >= 0; j--) { - m_DelayData.RemoveAt(DelArray[j]); - } - - for (int i = 0, sz = DelayDataForFieldAndControlIndex.GetSize(); i < sz; - i++) { - CJS_DelayData* pData = DelayDataForFieldAndControlIndex.GetAt(i); - Field::DoDelay(m_pDocument, pData); - DelayDataForFieldAndControlIndex.SetAt(i, NULL); - delete pData; - } + for (const auto& pData : DelayDataForFieldAndControlIndex) + Field::DoDelay(m_pDocument, pData.get()); } CJS_Document* Document::GetCJSDoc() const { diff --git a/fpdfsdk/javascript/Document.h b/fpdfsdk/javascript/Document.h index 8ae6c1d21d..03e885ce8e 100644 --- a/fpdfsdk/javascript/Document.h +++ b/fpdfsdk/javascript/Document.h @@ -275,7 +275,7 @@ class Document : public CJS_EmbedObj { CPDFSDK_Document* m_pDocument; CFX_WideString m_cwBaseURL; bool m_bDelay; - CFX_ArrayTemplate m_DelayData; + std::list> m_DelayData; }; class CJS_Document : public CJS_Object { -- cgit v1.2.3