diff options
author | Tom Sepez <tsepez@chromium.org> | 2016-03-15 12:34:17 -0700 |
---|---|---|
committer | Tom Sepez <tsepez@chromium.org> | 2016-03-15 12:34:17 -0700 |
commit | 56c1019e694ba9c2d6624d3c11d99c22798ffdc8 (patch) | |
tree | 6a62c930136d04784cb81ec0f321a6ede70d9c57 /fpdfsdk/javascript/Document.cpp | |
parent | aa403d3f68a966e24a6d8e8c109970930f096afb (diff) | |
download | pdfium-56c1019e694ba9c2d6624d3c11d99c22798ffdc8.tar.xz |
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 .
Diffstat (limited to 'fpdfsdk/javascript/Document.cpp')
-rw-r--r-- | fpdfsdk/javascript/Document.cpp | 62 |
1 files changed, 16 insertions, 46 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<CJS_DelayData*> 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<std::unique_ptr<CJS_DelayData>> 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<CJS_DelayData>(pData)); } void Document::DoFieldDelay(const CFX_WideString& sFieldName, int nControlIndex) { - CFX_DWordArray DelArray; - CFX_ArrayTemplate<CJS_DelayData*> 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<std::unique_ptr<CJS_DelayData>> 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 { |