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

Side by Side Diff: xfa/fgas/crt/fgas_memory.cpp

Issue 1951573002: Replace IFX_MemoryAllocator::Release() with delete. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 7 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/fgas/crt/fgas_memory.h ('k') | xfa/fxfa/app/xfa_textlayout.cpp » ('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/fgas/crt/fgas_memory.h" 7 #include "xfa/fgas/crt/fgas_memory.h"
8 8
9 #define MEMORY_TOOL_REPLACES_ALLOCATOR // Temporary, for CF testing. 9 #define MEMORY_TOOL_REPLACES_ALLOCATOR // Temporary, for CF testing.
10 10
11 #include <algorithm> 11 #include <algorithm>
12 12
13 #ifdef MEMORY_TOOL_REPLACES_ALLOCATOR 13 #ifdef MEMORY_TOOL_REPLACES_ALLOCATOR
14 14
15 namespace { 15 namespace {
16 16
17 class CFX_DefStore : public IFX_MemoryAllocator, public CFX_Target { 17 class CFX_DefStore : public IFX_MemoryAllocator, public CFX_Target {
18 public: 18 public:
19 CFX_DefStore() {} 19 CFX_DefStore() {}
20 ~CFX_DefStore() {} 20 ~CFX_DefStore() override {}
21 virtual void Release() { delete this; } 21 void* Alloc(size_t size) override { return FX_Alloc(uint8_t, size); }
22 virtual void* Alloc(size_t size) { return FX_Alloc(uint8_t, size); } 22 void Free(void* pBlock) override { FX_Free(pBlock); }
23 virtual void Free(void* pBlock) { FX_Free(pBlock); }
24 }; 23 };
25 24
26 } // namespace 25 } // namespace
27 26
28 IFX_MemoryAllocator* IFX_MemoryAllocator::Create(FX_ALLOCTYPE eType, 27 IFX_MemoryAllocator* IFX_MemoryAllocator::Create(FX_ALLOCTYPE eType,
29 size_t chunkSize, 28 size_t chunkSize,
30 size_t blockSize) { 29 size_t blockSize) {
31 return new CFX_DefStore(); 30 return new CFX_DefStore();
32 } 31 }
33 32
34 #else // MEMORY_TOOL_REPLACES_ALLOCATOR 33 #else // MEMORY_TOOL_REPLACES_ALLOCATOR
35 34
36 namespace { 35 namespace {
37 36
38 struct FX_STATICSTORECHUNK { 37 struct FX_STATICSTORECHUNK {
39 FX_STATICSTORECHUNK* pNextChunk; 38 FX_STATICSTORECHUNK* pNextChunk;
40 size_t iChunkSize; 39 size_t iChunkSize;
41 size_t iFreeSize; 40 size_t iFreeSize;
42 }; 41 };
43 42
44 class CFX_StaticStore : public IFX_MemoryAllocator, public CFX_Target { 43 class CFX_StaticStore : public IFX_MemoryAllocator, public CFX_Target {
45 public: 44 public:
46 CFX_StaticStore(size_t iDefChunkSize = 4096); 45 CFX_StaticStore(size_t iDefChunkSize = 4096);
47 ~CFX_StaticStore(); 46 ~CFX_StaticStore() override;
48 virtual void Release() { delete this; } 47 void* Alloc(size_t size) override;
49 virtual void* Alloc(size_t size); 48 void Free(void* pBlock) override {}
50 virtual void Free(void* pBlock) {}
51 49
52 protected: 50 protected:
53 size_t m_iAllocatedSize; 51 size_t m_iAllocatedSize;
54 size_t m_iDefChunkSize; 52 size_t m_iDefChunkSize;
55 FX_STATICSTORECHUNK* m_pChunk; 53 FX_STATICSTORECHUNK* m_pChunk;
56 FX_STATICSTORECHUNK* m_pLastChunk; 54 FX_STATICSTORECHUNK* m_pLastChunk;
57 FX_STATICSTORECHUNK* AllocChunk(size_t size); 55 FX_STATICSTORECHUNK* AllocChunk(size_t size);
58 FX_STATICSTORECHUNK* FindChunk(size_t size); 56 FX_STATICSTORECHUNK* FindChunk(size_t size);
59 }; 57 };
60 58
61 struct FX_FIXEDSTORECHUNK { 59 struct FX_FIXEDSTORECHUNK {
62 uint8_t* FirstFlag() { return reinterpret_cast<uint8_t*>(this + 1); } 60 uint8_t* FirstFlag() { return reinterpret_cast<uint8_t*>(this + 1); }
63 uint8_t* FirstBlock() { return FirstFlag() + iChunkSize; } 61 uint8_t* FirstBlock() { return FirstFlag() + iChunkSize; }
64 62
65 FX_FIXEDSTORECHUNK* pNextChunk; 63 FX_FIXEDSTORECHUNK* pNextChunk;
66 size_t iChunkSize; 64 size_t iChunkSize;
67 size_t iFreeNum; 65 size_t iFreeNum;
68 }; 66 };
69 67
70 class CFX_FixedStore : public IFX_MemoryAllocator, public CFX_Target { 68 class CFX_FixedStore : public IFX_MemoryAllocator, public CFX_Target {
71 public: 69 public:
72 CFX_FixedStore(size_t iBlockSize, size_t iBlockNumsInChunk); 70 CFX_FixedStore(size_t iBlockSize, size_t iBlockNumsInChunk);
73 virtual ~CFX_FixedStore(); 71 ~CFX_FixedStore() override;
74 virtual void Release() { delete this; } 72 void* Alloc(size_t size) override;
75 virtual void* Alloc(size_t size); 73 void Free(void* pBlock) override;
76 virtual void Free(void* pBlock);
77 74
78 protected: 75 protected:
79 FX_FIXEDSTORECHUNK* AllocChunk(); 76 FX_FIXEDSTORECHUNK* AllocChunk();
80 77
81 size_t m_iBlockSize; 78 size_t m_iBlockSize;
82 size_t m_iDefChunkSize; 79 size_t m_iDefChunkSize;
83 FX_FIXEDSTORECHUNK* m_pChunk; 80 FX_FIXEDSTORECHUNK* m_pChunk;
84 }; 81 };
85 82
86 } // namespace 83 } // namespace
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 } 240 }
244 } 241 }
245 size_t CFX_FixedStore::SetDefChunkSize(size_t iChunkSize) { 242 size_t CFX_FixedStore::SetDefChunkSize(size_t iChunkSize) {
246 ASSERT(iChunkSize != 0); 243 ASSERT(iChunkSize != 0);
247 size_t v = m_iDefChunkSize; 244 size_t v = m_iDefChunkSize;
248 m_iDefChunkSize = FX_4BYTEALIGN(iChunkSize); 245 m_iDefChunkSize = FX_4BYTEALIGN(iChunkSize);
249 return v; 246 return v;
250 } 247 }
251 248
252 #endif // MEMORY_TOOL_REPLACES_ALLOCATOR 249 #endif // MEMORY_TOOL_REPLACES_ALLOCATOR
OLDNEW
« no previous file with comments | « xfa/fgas/crt/fgas_memory.h ('k') | xfa/fxfa/app/xfa_textlayout.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698