From 8ed5366123840938d9a66a37108de826bf4f42e3 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Wed, 12 Apr 2017 14:26:14 -0400 Subject: Remove text buffer for CFGAS_TextStream MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The ::ReadString method appears to only be called in the CFDE_XMLSyntaxParser. The reads happen with a buffer size of 32k which seems like we won't have to call this too many times. Change-Id: I3ff522cdb081777b0b0433926392fb1a03455df3 Reviewed-on: https://pdfium-review.googlesource.com/4054 Commit-Queue: dsinclair Reviewed-by: Nicolás Peña Reviewed-by: Tom Sepez --- xfa/fgas/crt/ifgas_stream.cpp | 50 ++++++++++++++++--------------------------- 1 file changed, 18 insertions(+), 32 deletions(-) diff --git a/xfa/fgas/crt/ifgas_stream.cpp b/xfa/fgas/crt/ifgas_stream.cpp index 036176f873..38c94973d7 100644 --- a/xfa/fgas/crt/ifgas_stream.cpp +++ b/xfa/fgas/crt/ifgas_stream.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include "core/fxcrt/fx_ext.h" #include "third_party/base/ptr_util.h" @@ -165,8 +166,6 @@ class CFGAS_TextStream : public IFGAS_Stream { uint16_t m_wCodePage; int32_t m_wBOMLength; uint32_t m_dwBOM; - uint8_t* m_pBuf; - int32_t m_iBufSize; CFX_RetainPtr m_pStreamImp; }; @@ -336,17 +335,12 @@ CFGAS_TextStream::CFGAS_TextStream(const CFX_RetainPtr& pStream) : m_wCodePage(FX_CODEPAGE_DefANSI), m_wBOMLength(0), m_dwBOM(0), - m_pBuf(nullptr), - m_iBufSize(0), m_pStreamImp(pStream) { ASSERT(m_pStreamImp); InitStream(); } -CFGAS_TextStream::~CFGAS_TextStream() { - if (m_pBuf) - FX_Free(m_pBuf); -} +CFGAS_TextStream::~CFGAS_TextStream() {} void CFGAS_TextStream::InitStream() { int32_t iPosition = m_pStreamImp->GetPosition(); @@ -456,47 +450,39 @@ int32_t CFGAS_TextStream::ReadString(wchar_t* pStr, int32_t iMaxLength, bool& bEOS) { ASSERT(pStr && iMaxLength > 0); - if (!m_pStreamImp) { + if (!m_pStreamImp) return -1; - } - int32_t iLen; + if (m_wCodePage == FX_CODEPAGE_UTF16LE || m_wCodePage == FX_CODEPAGE_UTF16BE) { int32_t iBytes = iMaxLength * 2; - iLen = m_pStreamImp->ReadData((uint8_t*)pStr, iBytes); + int32_t iLen = m_pStreamImp->ReadData((uint8_t*)pStr, iBytes); iMaxLength = iLen / 2; - if (sizeof(wchar_t) > 2) { + if (sizeof(wchar_t) > 2) FX_UTF16ToWChar(pStr, iMaxLength); - } + #if _FX_ENDIAN_ == _FX_BIG_ENDIAN_ - if (m_wCodePage == FX_CODEPAGE_UTF16LE) { + if (m_wCodePage == FX_CODEPAGE_UTF16LE) FX_SwapByteOrder(pStr, iMaxLength); - } #else - if (m_wCodePage == FX_CODEPAGE_UTF16BE) { + if (m_wCodePage == FX_CODEPAGE_UTF16BE) FX_SwapByteOrder(pStr, iMaxLength); - } #endif + } else { int32_t pos = m_pStreamImp->GetPosition(); - int32_t iBytes = iMaxLength; - iBytes = std::min(iBytes, m_pStreamImp->GetLength() - pos); + int32_t iBytes = std::min(iMaxLength, m_pStreamImp->GetLength() - pos); if (iBytes > 0) { - if (!m_pBuf) { - m_pBuf = FX_Alloc(uint8_t, iBytes); - m_iBufSize = iBytes; - } else if (iBytes > m_iBufSize) { - m_pBuf = FX_Realloc(uint8_t, m_pBuf, iBytes); - m_iBufSize = iBytes; - } - iLen = m_pStreamImp->ReadData(m_pBuf, iBytes); + std::vector buf(iBytes); + + int32_t iLen = m_pStreamImp->ReadData(buf.data(), iBytes); int32_t iSrc = iLen; - int32_t iDecode = FX_DecodeString(m_wCodePage, (const char*)m_pBuf, &iSrc, - pStr, &iMaxLength, true); + int32_t iDecode = FX_DecodeString( + m_wCodePage, reinterpret_cast(buf.data()), &iSrc, pStr, + &iMaxLength, true); m_pStreamImp->Seek(FX_STREAMSEEK_Current, iSrc - iLen); - if (iDecode < 1) { + if (iDecode < 1) return -1; - } } else { iMaxLength = 0; } -- cgit v1.2.3