Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(367)

Side by Side Diff: core/fpdfapi/page/cpdf_streamparser.cpp

Issue 2520953004: Avoid calls to WrapUnique in CPDF_streamparser (Closed)
Patch Set: assign unique_ptr Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/fpdfapi/page/cpdf_streamcontentparser.cpp ('k') | core/fpdfapi/page/pageint.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "core/fpdfapi/page/pageint.h" 7 #include "core/fpdfapi/page/pageint.h"
8 8
9 #include <limits.h> 9 #include <limits.h>
10 10
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 const CFX_WeakPtr<CFX_ByteStringPool>& pPool) 121 const CFX_WeakPtr<CFX_ByteStringPool>& pPool)
122 : m_pBuf(pData), 122 : m_pBuf(pData),
123 m_Size(dwSize), 123 m_Size(dwSize),
124 m_Pos(0), 124 m_Pos(0),
125 m_pPool(pPool) {} 125 m_pPool(pPool) {}
126 126
127 CPDF_StreamParser::~CPDF_StreamParser() {} 127 CPDF_StreamParser::~CPDF_StreamParser() {}
128 128
129 std::unique_ptr<CPDF_Stream> CPDF_StreamParser::ReadInlineStream( 129 std::unique_ptr<CPDF_Stream> CPDF_StreamParser::ReadInlineStream(
130 CPDF_Document* pDoc, 130 CPDF_Document* pDoc,
131 CPDF_Dictionary* pDict, 131 std::unique_ptr<CPDF_Dictionary> pDict,
132 CPDF_Object* pCSObj) { 132 CPDF_Object* pCSObj) {
133 if (m_Pos == m_Size) 133 if (m_Pos == m_Size)
134 return nullptr; 134 return nullptr;
135 135
136 if (PDFCharIsWhitespace(m_pBuf[m_Pos])) 136 if (PDFCharIsWhitespace(m_pBuf[m_Pos]))
137 m_Pos++; 137 m_Pos++;
138 138
139 CFX_ByteString Decoder; 139 CFX_ByteString Decoder;
140 CPDF_Dictionary* pParam = nullptr; 140 CPDF_Dictionary* pParam = nullptr;
141 CPDF_Object* pFilter = pDict->GetDirectObjectFor("Filter"); 141 CPDF_Object* pFilter = pDict->GetDirectObjectFor("Filter");
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 break; 224 break;
225 } 225 }
226 dwStreamSize += m_Pos - dwPrevPos; 226 dwStreamSize += m_Pos - dwPrevPos;
227 } 227 }
228 m_Pos = dwSavePos; 228 m_Pos = dwSavePos;
229 pData = FX_Alloc(uint8_t, dwStreamSize); 229 pData = FX_Alloc(uint8_t, dwStreamSize);
230 FXSYS_memcpy(pData, m_pBuf + m_Pos, dwStreamSize); 230 FXSYS_memcpy(pData, m_pBuf + m_Pos, dwStreamSize);
231 m_Pos += dwStreamSize; 231 m_Pos += dwStreamSize;
232 } 232 }
233 pDict->SetNewFor<CPDF_Number>("Length", (int)dwStreamSize); 233 pDict->SetNewFor<CPDF_Number>("Length", (int)dwStreamSize);
234 return pdfium::MakeUnique<CPDF_Stream>(pData, dwStreamSize, 234 return pdfium::MakeUnique<CPDF_Stream>(pData, dwStreamSize, std::move(pDict));
235 pdfium::WrapUnique(pDict));
236 } 235 }
237 236
238 CPDF_StreamParser::SyntaxType CPDF_StreamParser::ParseNextElement() { 237 CPDF_StreamParser::SyntaxType CPDF_StreamParser::ParseNextElement() {
239 m_pLastObj.reset(); 238 m_pLastObj.reset();
240 m_WordSize = 0; 239 m_WordSize = 0;
241 if (!PositionIsInBounds()) 240 if (!PositionIsInBounds())
242 return EndOfData; 241 return EndOfData;
243 242
244 int ch = m_pBuf[m_Pos++]; 243 int ch = m_pBuf[m_Pos++];
245 while (1) { 244 while (1) {
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 605
607 if (buf.GetLength() > kMaxStringLength) 606 if (buf.GetLength() > kMaxStringLength)
608 return CFX_ByteString(buf.GetBuffer(), kMaxStringLength); 607 return CFX_ByteString(buf.GetBuffer(), kMaxStringLength);
609 608
610 return buf.MakeString(); 609 return buf.MakeString();
611 } 610 }
612 611
613 bool CPDF_StreamParser::PositionIsInBounds() const { 612 bool CPDF_StreamParser::PositionIsInBounds() const {
614 return m_Pos < m_Size; 613 return m_Pos < m_Size;
615 } 614 }
OLDNEW
« no previous file with comments | « core/fpdfapi/page/cpdf_streamcontentparser.cpp ('k') | core/fpdfapi/page/pageint.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698