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

Side by Side Diff: xfa/fgas/crt/fgas_memory.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/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 #ifndef MEMORY_TOOL_REPLACES_ALLOCATOR 9 #ifndef MEMORY_TOOL_REPLACES_ALLOCATOR
10 #define MEMORY_TOOL_REPLACES_ALLOCATOR // Temporary, for CF testing. 10 #define MEMORY_TOOL_REPLACES_ALLOCATOR // Temporary, for CF testing.
11 #endif 11 #endif
12 12
13 #include <algorithm> 13 #include <algorithm>
14 14
15 #ifdef MEMORY_TOOL_REPLACES_ALLOCATOR 15 #ifdef MEMORY_TOOL_REPLACES_ALLOCATOR
16 16
17 namespace { 17 namespace {
18 18
19 class CFX_DefStore : public IFX_MemoryAllocator, public CFX_Target { 19 class CFX_DefStore : public IFX_MemoryAllocator, public CFX_Target {
20 public: 20 public:
21 CFX_DefStore() {} 21 CFX_DefStore() {}
22 ~CFX_DefStore() override {} 22 ~CFX_DefStore() override {}
23 23
24 void* Alloc(size_t size) override { return FX_Alloc(uint8_t, size); } 24 void* Alloc(size_t size) override { return FX_Alloc(uint8_t, size); }
25 void Free(void* pBlock) override { FX_Free(pBlock); } 25 void Free(void* pBlock) override { FX_Free(pBlock); }
26 }; 26 };
27 27
28 } // namespace 28 } // namespace
29 29
30 IFX_MemoryAllocator* IFX_MemoryAllocator::Create(FX_ALLOCTYPE eType, 30 std::unique_ptr<IFX_MemoryAllocator> IFX_MemoryAllocator::Create(
31 size_t chunkSize, 31 FX_ALLOCTYPE eType,
32 size_t blockSize) { 32 size_t chunkSize,
33 return new CFX_DefStore(); 33 size_t blockSize) {
34 return std::unique_ptr<IFX_MemoryAllocator>(new CFX_DefStore());
34 } 35 }
35 36
36 #else // MEMORY_TOOL_REPLACES_ALLOCATOR 37 #else // MEMORY_TOOL_REPLACES_ALLOCATOR
37 38
38 namespace { 39 namespace {
39 40
40 struct FX_STATICSTORECHUNK { 41 struct FX_STATICSTORECHUNK {
41 FX_STATICSTORECHUNK* pNextChunk; 42 FX_STATICSTORECHUNK* pNextChunk;
42 size_t iChunkSize; 43 size_t iChunkSize;
43 size_t iFreeSize; 44 size_t iFreeSize;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 82
82 size_t m_iBlockSize; 83 size_t m_iBlockSize;
83 size_t m_iDefChunkSize; 84 size_t m_iDefChunkSize;
84 FX_FIXEDSTORECHUNK* m_pChunk; 85 FX_FIXEDSTORECHUNK* m_pChunk;
85 }; 86 };
86 87
87 } // namespace 88 } // namespace
88 89
89 #define FX_4BYTEALIGN(size) (((size) + 3) & ~3) 90 #define FX_4BYTEALIGN(size) (((size) + 3) & ~3)
90 91
91 IFX_MemoryAllocator* IFX_MemoryAllocator::Create(FX_ALLOCTYPE eType, 92 std::unique_ptr<IFX_MemoryAllocator> IFX_MemoryAllocator::Create(
92 size_t chunkSize, 93 FX_ALLOCTYPE eType,
93 size_t blockSize) { 94 size_t chunkSize,
95 size_t blockSize) {
94 switch (eType) { 96 switch (eType) {
95 case FX_ALLOCTYPE_Static: 97 case FX_ALLOCTYPE_Static:
96 return new CFX_StaticStore(chunkSize); 98 return std::unique_ptr<IFX_MemoryAllocator>(
99 new CFX_StaticStore(chunkSize));
97 case FX_ALLOCTYPE_Fixed: 100 case FX_ALLOCTYPE_Fixed:
98 return new CFX_FixedStore(blockSize, chunkSize); 101 return std::unique_ptr<IFX_MemoryAllocator>(new CFX_FixedStore(blockSize, chunkSize);
99 default: 102 default:
100 ASSERT(0); 103 ASSERT(0);
101 return nullptr; 104 return std::unique_ptr<IFX_MemoryAllocator>();
102 } 105 }
103 } 106 }
104 107
105 CFX_StaticStore::CFX_StaticStore(size_t iDefChunkSize) 108 CFX_StaticStore::CFX_StaticStore(size_t iDefChunkSize)
106 : m_iAllocatedSize(0), 109 : m_iAllocatedSize(0),
107 m_iDefChunkSize(iDefChunkSize), 110 m_iDefChunkSize(iDefChunkSize),
108 m_pChunk(nullptr), 111 m_pChunk(nullptr),
109 m_pLastChunk(nullptr) { 112 m_pLastChunk(nullptr) {
110 ASSERT(m_iDefChunkSize != 0); 113 ASSERT(m_iDefChunkSize != 0);
111 } 114 }
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 } 247 }
245 } 248 }
246 size_t CFX_FixedStore::SetDefChunkSize(size_t iChunkSize) { 249 size_t CFX_FixedStore::SetDefChunkSize(size_t iChunkSize) {
247 ASSERT(iChunkSize != 0); 250 ASSERT(iChunkSize != 0);
248 size_t v = m_iDefChunkSize; 251 size_t v = m_iDefChunkSize;
249 m_iDefChunkSize = FX_4BYTEALIGN(iChunkSize); 252 m_iDefChunkSize = FX_4BYTEALIGN(iChunkSize);
250 return v; 253 return v;
251 } 254 }
252 255
253 #endif // MEMORY_TOOL_REPLACES_ALLOCATOR 256 #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