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

Unified Diff: core/include/fxcrt/fx_basic.h

Issue 1719543002: Tidy CFX_FixedBufGrow. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: explicit. Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/include/fxcrt/fx_basic.h
diff --git a/core/include/fxcrt/fx_basic.h b/core/include/fxcrt/fx_basic.h
index 018a91462e5ea61c57fce4bf1149eae496349fe8..9b1eaa5bf518722c1f36c2056438faf8b8e5dc01 100644
--- a/core/include/fxcrt/fx_basic.h
+++ b/core/include/fxcrt/fx_basic.h
@@ -576,33 +576,24 @@ class CFX_SegmentedArray : public CFX_BaseSegmentedArray {
}
};
#endif // PDF_ENABLE_XFA
+
template <class DataType, int FixedSize>
class CFX_FixedBufGrow {
public:
- CFX_FixedBufGrow() : m_pData(NULL) {}
- CFX_FixedBufGrow(int data_size) : m_pData(NULL) {
- if (data_size > FixedSize) {
- m_pData = FX_Alloc(DataType, data_size);
- } else {
- FXSYS_memset(m_Data, 0, sizeof(DataType) * FixedSize);
- }
- }
- void SetDataSize(int data_size) {
- FX_Free(m_pData);
- m_pData = NULL;
+ explicit CFX_FixedBufGrow(int data_size) {
if (data_size > FixedSize) {
- m_pData = FX_Alloc(DataType, data_size);
- } else {
- FXSYS_memset(m_Data, 0, sizeof(DataType) * FixedSize);
+ m_pGrowData.reset(FX_Alloc(DataType, data_size));
+ return;
}
+ FXSYS_memset(m_FixedData, 0, sizeof(DataType) * FixedSize);
}
- ~CFX_FixedBufGrow() { FX_Free(m_pData); }
- operator DataType*() { return m_pData ? m_pData : m_Data; }
+ operator DataType*() { return m_pGrowData ? m_pGrowData.get() : m_FixedData; }
private:
- DataType m_Data[FixedSize];
- DataType* m_pData;
+ DataType m_FixedData[FixedSize];
+ std::unique_ptr<DataType, FxFreeDeleter> m_pGrowData;
};
+
#ifdef PDF_ENABLE_XFA
class CFX_MapPtrToPtr {
protected:
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698