OLD | NEW |
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), |
20 m_nTotal(0), | 20 m_nTotal(0), |
21 m_bChanged(FALSE), | 21 m_bChanged(FALSE), |
22 m_pAllocator(NULL) { | 22 m_pAllocator(nullptr) { |
23 ASSERT(m_nChunkSize); | 23 ASSERT(m_nChunkSize); |
24 ResetChunkBuffer(kDefaultChunkCount, m_nChunkSize); | 24 ResetChunkBuffer(kDefaultChunkCount, m_nChunkSize); |
25 } | 25 } |
26 | 26 |
27 CFDE_TxtEdtBuf::~CFDE_TxtEdtBuf() { | 27 CFDE_TxtEdtBuf::~CFDE_TxtEdtBuf() { |
28 Clear(TRUE); | 28 Clear(TRUE); |
29 delete m_pAllocator; | 29 delete m_pAllocator; |
30 m_Chunks.RemoveAll(); | 30 m_Chunks.RemoveAll(); |
31 } | 31 } |
32 | 32 |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 nLength -= nDelete; | 189 nLength -= nDelete; |
190 cpEnd.nChunkIndex--; | 190 cpEnd.nChunkIndex--; |
191 } | 191 } |
192 while (nLength > 0) { | 192 while (nLength > 0) { |
193 lpChunk = m_Chunks[cpEnd.nChunkIndex]; | 193 lpChunk = m_Chunks[cpEnd.nChunkIndex]; |
194 int32_t nDeleted = std::min(lpChunk->nUsed, nLength); | 194 int32_t nDeleted = std::min(lpChunk->nUsed, nLength); |
195 lpChunk->nUsed -= nDeleted; | 195 lpChunk->nUsed -= nDeleted; |
196 if (lpChunk->nUsed == 0) { | 196 if (lpChunk->nUsed == 0) { |
197 m_pAllocator->Free(lpChunk); | 197 m_pAllocator->Free(lpChunk); |
198 m_Chunks.RemoveAt(cpEnd.nChunkIndex); | 198 m_Chunks.RemoveAt(cpEnd.nChunkIndex); |
199 lpChunk = NULL; | 199 lpChunk = nullptr; |
200 } | 200 } |
201 nLength -= nDeleted; | 201 nLength -= nDeleted; |
202 cpEnd.nChunkIndex--; | 202 cpEnd.nChunkIndex--; |
203 } | 203 } |
204 m_bChanged = TRUE; | 204 m_bChanged = TRUE; |
205 } | 205 } |
206 | 206 |
207 void CFDE_TxtEdtBuf::Clear(FX_BOOL bRelease) { | 207 void CFDE_TxtEdtBuf::Clear(FX_BOOL bRelease) { |
208 int32_t i = 0; | 208 int32_t i = 0; |
209 int32_t nCount = m_Chunks.GetSize(); | 209 int32_t nCount = m_Chunks.GetSize(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 FXSYS_memcpy(lpPreChunk->wChars + lpPreChunk->nUsed, lpCurChunk->wChars, | 253 FXSYS_memcpy(lpPreChunk->wChars + lpPreChunk->nUsed, lpCurChunk->wChars, |
254 lpCurChunk->nUsed * sizeof(FX_WCHAR)); | 254 lpCurChunk->nUsed * sizeof(FX_WCHAR)); |
255 lpPreChunk->nUsed += lpCurChunk->nUsed; | 255 lpPreChunk->nUsed += lpCurChunk->nUsed; |
256 m_pAllocator->Free(lpCurChunk); | 256 m_pAllocator->Free(lpCurChunk); |
257 m_Chunks.RemoveAt(i); | 257 m_Chunks.RemoveAt(i); |
258 --i; | 258 --i; |
259 --nCount; | 259 --nCount; |
260 } else { | 260 } else { |
261 lpPreChunk = lpCurChunk; | 261 lpPreChunk = lpCurChunk; |
262 } | 262 } |
263 if (pPause != NULL && pPause->NeedToPauseNow()) { | 263 if (pPause && pPause->NeedToPauseNow()) |
264 return FALSE; | 264 return FALSE; |
265 } | |
266 } | 265 } |
267 m_bChanged = FALSE; | 266 m_bChanged = FALSE; |
268 return TRUE; | 267 return TRUE; |
269 } | 268 } |
270 | 269 |
271 void CFDE_TxtEdtBuf::ResetChunkBuffer(int32_t nDefChunkCount, | 270 void CFDE_TxtEdtBuf::ResetChunkBuffer(int32_t nDefChunkCount, |
272 int32_t nChunkSize) { | 271 int32_t nChunkSize) { |
273 ASSERT(nChunkSize); | 272 ASSERT(nChunkSize); |
274 ASSERT(nDefChunkCount); | 273 ASSERT(nDefChunkCount); |
275 delete m_pAllocator; | 274 delete m_pAllocator; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 int32_t nCount = m_Chunks.GetSize(); | 308 int32_t nCount = m_Chunks.GetSize(); |
310 for (; i < nCount; i++) { | 309 for (; i < nCount; i++) { |
311 nTotal += m_Chunks[i]->nUsed; | 310 nTotal += m_Chunks[i]->nUsed; |
312 if (nTotal > nIndex) { | 311 if (nTotal > nIndex) { |
313 break; | 312 break; |
314 } | 313 } |
315 } | 314 } |
316 cp.nChunkIndex = i; | 315 cp.nChunkIndex = i; |
317 cp.nCharIndex = m_Chunks[i]->nUsed - (nTotal - nIndex); | 316 cp.nCharIndex = m_Chunks[i]->nUsed - (nTotal - nIndex); |
318 } | 317 } |
OLD | NEW |