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

Side by Side Diff: xfa/fde/cfde_txtedtbuf.cpp

Issue 2208423002: Use smart pointers for class owned pointers under xfa/fde (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: one more change Created 4 years, 4 months 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 | « xfa/fde/cfde_txtedtbuf.h ('k') | xfa/fde/cfde_txtedtengine.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 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 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 "xfa/fde/cfde_txtedtbuf.h" 7 #include "xfa/fde/cfde_txtedtbuf.h"
8 8
9 #include "xfa/fgas/crt/fgas_memory.h" 9 #include "xfa/fgas/crt/fgas_memory.h"
10 10
11 namespace { 11 namespace {
12 12
13 const int kDefaultChunkSize = 1024; 13 const int kDefaultChunkSize = 1024;
14 const int kDefaultChunkCount = 2; 14 const int kDefaultChunkCount = 2;
15 15
16 } // namespace 16 } // namespace
17 17
18 CFDE_TxtEdtBuf::CFDE_TxtEdtBuf() 18 CFDE_TxtEdtBuf::CFDE_TxtEdtBuf()
19 : m_nChunkSize(kDefaultChunkSize), 19 : m_nChunkSize(kDefaultChunkSize), m_nTotal(0), m_bChanged(FALSE) {
20 m_nTotal(0),
21 m_bChanged(FALSE),
22 m_pAllocator(nullptr) {
23 ASSERT(m_nChunkSize);
24 ResetChunkBuffer(kDefaultChunkCount, m_nChunkSize); 20 ResetChunkBuffer(kDefaultChunkCount, m_nChunkSize);
25 } 21 }
26 22
27 CFDE_TxtEdtBuf::~CFDE_TxtEdtBuf() { 23 CFDE_TxtEdtBuf::~CFDE_TxtEdtBuf() {
28 Clear(TRUE); 24 Clear(TRUE);
29 delete m_pAllocator;
30 m_Chunks.RemoveAll(); 25 m_Chunks.RemoveAll();
31 } 26 }
32 27
33 int32_t CFDE_TxtEdtBuf::GetChunkSize() const { 28 int32_t CFDE_TxtEdtBuf::GetChunkSize() const {
34 return m_nChunkSize; 29 return m_nChunkSize;
35 } 30 }
36 31
37 int32_t CFDE_TxtEdtBuf::GetTextLength() const { 32 int32_t CFDE_TxtEdtBuf::GetTextLength() const {
38 return m_nTotal; 33 return m_nTotal;
39 } 34 }
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 return FALSE; 259 return FALSE;
265 } 260 }
266 m_bChanged = FALSE; 261 m_bChanged = FALSE;
267 return TRUE; 262 return TRUE;
268 } 263 }
269 264
270 void CFDE_TxtEdtBuf::ResetChunkBuffer(int32_t nDefChunkCount, 265 void CFDE_TxtEdtBuf::ResetChunkBuffer(int32_t nDefChunkCount,
271 int32_t nChunkSize) { 266 int32_t nChunkSize) {
272 ASSERT(nChunkSize); 267 ASSERT(nChunkSize);
273 ASSERT(nDefChunkCount); 268 ASSERT(nDefChunkCount);
274 delete m_pAllocator;
275 m_pAllocator = nullptr;
276 m_Chunks.RemoveAll(); 269 m_Chunks.RemoveAll();
277 m_nChunkSize = nChunkSize; 270 m_nChunkSize = nChunkSize;
278 int32_t nChunkLength = 271 int32_t nChunkLength =
279 sizeof(FDE_CHUNKHEADER) + (m_nChunkSize - 1) * sizeof(FX_WCHAR); 272 sizeof(FDE_CHUNKHEADER) + (m_nChunkSize - 1) * sizeof(FX_WCHAR);
280 m_pAllocator = IFX_MemoryAllocator::Create(FX_ALLOCTYPE_Fixed, nDefChunkCount, 273 m_pAllocator = IFX_MemoryAllocator::Create(FX_ALLOCTYPE_Fixed, nDefChunkCount,
281 nChunkLength); 274 nChunkLength);
282 FDE_CHUNKHEADER* lpChunkHeader = 275 FDE_CHUNKHEADER* lpChunkHeader =
283 static_cast<FDE_CHUNKHEADER*>(m_pAllocator->Alloc(nChunkLength)); 276 static_cast<FDE_CHUNKHEADER*>(m_pAllocator->Alloc(nChunkLength));
284 ASSERT(lpChunkHeader); 277 ASSERT(lpChunkHeader);
285 lpChunkHeader->nUsed = 0; 278 lpChunkHeader->nUsed = 0;
(...skipping 22 matching lines...) Expand all
308 int32_t nCount = m_Chunks.GetSize(); 301 int32_t nCount = m_Chunks.GetSize();
309 for (; i < nCount; i++) { 302 for (; i < nCount; i++) {
310 nTotal += m_Chunks[i]->nUsed; 303 nTotal += m_Chunks[i]->nUsed;
311 if (nTotal > nIndex) { 304 if (nTotal > nIndex) {
312 break; 305 break;
313 } 306 }
314 } 307 }
315 cp.nChunkIndex = i; 308 cp.nChunkIndex = i;
316 cp.nCharIndex = m_Chunks[i]->nUsed - (nTotal - nIndex); 309 cp.nCharIndex = m_Chunks[i]->nUsed - (nTotal - nIndex);
317 } 310 }
OLDNEW
« no previous file with comments | « xfa/fde/cfde_txtedtbuf.h ('k') | xfa/fde/cfde_txtedtengine.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698