diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-04-12 14:26:14 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-04-12 18:38:38 +0000 |
commit | 8ed5366123840938d9a66a37108de826bf4f42e3 (patch) | |
tree | 1d9ec73a565c0beca4be90133d2cee46147540c9 /xfa/fgas/crt | |
parent | 941c1b8567584acdbe12ea62dee9dabab09f119f (diff) | |
download | pdfium-8ed5366123840938d9a66a37108de826bf4f42e3.tar.xz |
Remove text buffer for CFGAS_TextStream
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 <dsinclair@chromium.org>
Reviewed-by: Nicolás Peña <npm@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'xfa/fgas/crt')
-rw-r--r-- | xfa/fgas/crt/ifgas_stream.cpp | 50 |
1 files 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 <algorithm> #include <memory> #include <utility> +#include <vector> #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<IFGAS_Stream> m_pStreamImp; }; @@ -336,17 +335,12 @@ CFGAS_TextStream::CFGAS_TextStream(const CFX_RetainPtr<IFGAS_Stream>& 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<uint8_t> 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<const char*>(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; } |