From cfdb5fdd12d47136ad1db9a67fc598a71f6757ff Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Wed, 15 Mar 2017 12:48:38 -0700 Subject: remove CFX_ArrayTemplate from fde/xml. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I62499a271e753e44234412fd855fbd8a56763d71 Reviewed-on: https://pdfium-review.googlesource.com/3055 Reviewed-by: Nicolás Peña Commit-Queue: Tom Sepez --- xfa/fde/xml/cfx_saxreader.cpp | 53 ++++++++++++++++++++----------------------- xfa/fde/xml/cfx_saxreader.h | 2 +- xfa/fde/xml/fde_xml_imp.cpp | 42 ++++++++++++++-------------------- xfa/fde/xml/fde_xml_imp.h | 2 +- 4 files changed, 43 insertions(+), 56 deletions(-) diff --git a/xfa/fde/xml/cfx_saxreader.cpp b/xfa/fde/xml/cfx_saxreader.cpp index 458bed52d6..552ec5f5fe 100644 --- a/xfa/fde/xml/cfx_saxreader.cpp +++ b/xfa/fde/xml/cfx_saxreader.cpp @@ -10,6 +10,7 @@ #include #include "third_party/base/ptr_util.h" +#include "third_party/base/stl_util.h" #include "xfa/fxfa/xfa_checksum.h" enum class CFX_SaxMode { @@ -147,11 +148,9 @@ CFX_SAXReader::~CFX_SAXReader() { void CFX_SAXReader::Reset() { m_File.Reset(); - while (!m_Stack.empty()) - m_Stack.pop(); - + m_Stack = std::stack>(); m_dwItemID = 0; - m_SkipStack.RemoveAll(); + m_SkipStack = std::stack(); m_SkipChar = 0; m_iDataLength = 0; m_iEntityStart = -1; @@ -397,17 +396,17 @@ void CFX_SAXReader::ParseDeclOrComment() { GetCurrentItem()->m_eNode = CFX_SAXItem::Type::Comment; if (!m_pCommentContext) m_pCommentContext = new CFX_SAXCommentContext; - m_pCommentContext->m_iHeaderCount = 1; m_pCommentContext->m_iTailCount = 0; - } else { - m_eMode = CFX_SaxMode::DeclNode; - m_dwDataOffset = m_File.m_dwBufIndex; - m_SkipChar = '>'; - m_SkipStack.Add('>'); - SkipNode(); + return; } + m_eMode = CFX_SaxMode::DeclNode; + m_dwDataOffset = m_File.m_dwBufIndex; + m_SkipChar = '>'; + m_SkipStack.push('>'); + SkipNode(); } + void CFX_SAXReader::ParseComment() { m_pCommentContext->m_iHeaderCount = 2; m_dwNodePos = m_File.m_dwCur + m_File.m_dwBufIndex; @@ -591,44 +590,41 @@ void CFX_SAXReader::ParseTargetData() { } } void CFX_SAXReader::SkipNode() { - int32_t iLen = m_SkipStack.GetSize(); if (m_SkipChar == '\'' || m_SkipChar == '\"') { - if (m_CurByte != m_SkipChar) { + if (m_CurByte != m_SkipChar) return; - } - iLen--; - ASSERT(iLen > -1); - m_SkipStack.RemoveAt(iLen, 1); - m_SkipChar = iLen ? m_SkipStack[iLen - 1] : 0; + + ASSERT(!m_SkipStack.empty()); + m_SkipStack.pop(); + m_SkipChar = !m_SkipStack.empty() ? m_SkipStack.top() : 0; return; } switch (m_CurByte) { case '<': m_SkipChar = '>'; - m_SkipStack.Add('>'); + m_SkipStack.push('>'); break; case '[': m_SkipChar = ']'; - m_SkipStack.Add(']'); + m_SkipStack.push(']'); break; case '(': m_SkipChar = ')'; - m_SkipStack.Add(')'); + m_SkipStack.push(')'); break; case '\'': m_SkipChar = '\''; - m_SkipStack.Add('\''); + m_SkipStack.push('\''); break; case '\"': m_SkipChar = '\"'; - m_SkipStack.Add('\"'); + m_SkipStack.push('\"'); break; default: if (m_CurByte == m_SkipChar) { - iLen--; - m_SkipStack.RemoveAt(iLen, 1); - m_SkipChar = iLen ? m_SkipStack[iLen - 1] : 0; - if (iLen == 0 && m_CurByte == '>') { + m_SkipStack.pop(); + m_SkipChar = !m_SkipStack.empty() ? m_SkipStack.top() : 0; + if (m_SkipStack.empty() && m_CurByte == '>') { m_iDataLength = m_iDataPos; m_iDataPos = 0; if (m_iDataLength >= 9 && @@ -653,9 +649,8 @@ void CFX_SAXReader::SkipNode() { } break; } - if (iLen > 0) { + if (!m_SkipStack.empty()) ParseChar(m_CurByte); - } } void CFX_SAXReader::NotifyData() { diff --git a/xfa/fde/xml/cfx_saxreader.h b/xfa/fde/xml/cfx_saxreader.h index 129399d88d..4e36615429 100644 --- a/xfa/fde/xml/cfx_saxreader.h +++ b/xfa/fde/xml/cfx_saxreader.h @@ -128,7 +128,7 @@ class CFX_SAXReader { bool m_bCharData; uint8_t m_CurByte; uint32_t m_dwDataOffset; - CFX_ArrayTemplate m_SkipStack; + std::stack m_SkipStack; uint8_t m_SkipChar; uint32_t m_dwNodePos; uint8_t* m_pszData; diff --git a/xfa/fde/xml/fde_xml_imp.cpp b/xfa/fde/xml/fde_xml_imp.cpp index 334410049c..28384451e4 100644 --- a/xfa/fde/xml/fde_xml_imp.cpp +++ b/xfa/fde/xml/fde_xml_imp.cpp @@ -1111,26 +1111,25 @@ CFDE_BlockBuffer::~CFDE_BlockBuffer() { wchar_t* CFDE_BlockBuffer::GetAvailableBlock(int32_t& iIndexInBlock) { iIndexInBlock = 0; - if (!m_BlockArray.GetSize()) { + if (m_BlockArray.empty()) return nullptr; - } + int32_t iRealIndex = m_iStartPosition + m_iDataLength; if (iRealIndex == m_iBufferSize) { - wchar_t* pBlock = FX_Alloc(wchar_t, m_iAllocStep); - m_BlockArray.Add(pBlock); + m_BlockArray.emplace_back(FX_Alloc(wchar_t, m_iAllocStep)); m_iBufferSize += m_iAllocStep; - return pBlock; + return m_BlockArray.back().get(); } iIndexInBlock = iRealIndex % m_iAllocStep; - return m_BlockArray[iRealIndex / m_iAllocStep]; + return m_BlockArray[iRealIndex / m_iAllocStep].get(); } bool CFDE_BlockBuffer::InitBuffer(int32_t iBufferSize) { ClearBuffer(); int32_t iNumOfBlock = (iBufferSize - 1) / m_iAllocStep + 1; - for (int32_t i = 0; i < iNumOfBlock; i++) { - m_BlockArray.Add(FX_Alloc(wchar_t, m_iAllocStep)); - } + for (int32_t i = 0; i < iNumOfBlock; i++) + m_BlockArray.emplace_back(FX_Alloc(wchar_t, m_iAllocStep)); + m_iBufferSize = iNumOfBlock * m_iAllocStep; return true; } @@ -1142,26 +1141,23 @@ void CFDE_BlockBuffer::SetTextChar(int32_t iIndex, wchar_t ch) { int32_t iRealIndex = m_iStartPosition + iIndex; int32_t iBlockIndex = iRealIndex / m_iAllocStep; int32_t iInnerIndex = iRealIndex % m_iAllocStep; - int32_t iBlockSize = m_BlockArray.GetSize(); + int32_t iBlockSize = pdfium::CollectionSize(m_BlockArray); if (iBlockIndex >= iBlockSize) { int32_t iNewBlocks = iBlockIndex - iBlockSize + 1; do { - wchar_t* pBlock = FX_Alloc(wchar_t, m_iAllocStep); - m_BlockArray.Add(pBlock); + m_BlockArray.emplace_back(FX_Alloc(wchar_t, m_iAllocStep)); m_iBufferSize += m_iAllocStep; } while (--iNewBlocks); } - wchar_t* pTextData = m_BlockArray[iBlockIndex]; - *(pTextData + iInnerIndex) = ch; - if (m_iDataLength <= iIndex) { - m_iDataLength = iIndex + 1; - } + wchar_t* pTextData = m_BlockArray[iBlockIndex].get(); + pTextData[iInnerIndex] = ch; + m_iDataLength = std::max(m_iDataLength, iIndex + 1); } int32_t CFDE_BlockBuffer::DeleteTextChars(int32_t iCount, bool bDirection) { - if (iCount <= 0) { + if (iCount <= 0) return m_iDataLength; - } + if (iCount >= m_iDataLength) { Reset(false); return 0; @@ -1210,7 +1206,7 @@ void CFDE_BlockBuffer::GetTextData(CFX_WideString& wsTextData, if (i == iEndBlockIndex) { iCopyLength -= ((m_iAllocStep - 1) - iEndInnerIndex); } - wchar_t* pBlockBuf = m_BlockArray[i]; + wchar_t* pBlockBuf = m_BlockArray[i].get(); FXSYS_memcpy(pBuf + iPointer, pBlockBuf + iBufferPointer, iCopyLength * sizeof(wchar_t)); iPointer += iCopyLength; @@ -1229,11 +1225,7 @@ void CFDE_BlockBuffer::TextDataIndex2BufIndex(const int32_t iIndex, void CFDE_BlockBuffer::ClearBuffer() { m_iBufferSize = 0; - int32_t iSize = m_BlockArray.GetSize(); - for (int32_t i = 0; i < iSize; i++) { - FX_Free(m_BlockArray[i]); - } - m_BlockArray.RemoveAll(); + m_BlockArray.clear(); } CFDE_XMLSyntaxParser::CFDE_XMLSyntaxParser() diff --git a/xfa/fde/xml/fde_xml_imp.h b/xfa/fde/xml/fde_xml_imp.h index ab5ab9be24..687a0cd416 100644 --- a/xfa/fde/xml/fde_xml_imp.h +++ b/xfa/fde/xml/fde_xml_imp.h @@ -243,7 +243,7 @@ class CFDE_BlockBuffer { int32_t& iInnerIndex) const; void ClearBuffer(); - CFX_ArrayTemplate m_BlockArray; + std::vector> m_BlockArray; int32_t m_iDataLength; int32_t m_iBufferSize; int32_t m_iAllocStep; -- cgit v1.2.3