summaryrefslogtreecommitdiff
path: root/core/include
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2016-02-19 16:26:53 -0800
committerTom Sepez <tsepez@chromium.org>2016-02-19 16:26:53 -0800
commit33364e2d6f9549d7964611097c663264548a5d68 (patch)
tree708cba09d73b868c0be3037793b9629b6e90f8e8 /core/include
parentac121aa23a5ee3290af151dddbbdc0f4644098d4 (diff)
downloadpdfium-33364e2d6f9549d7964611097c663264548a5d68.tar.xz
Tidy CFX_FixedBufGrow.
Stop short of removing it since it looks like it may be used in some very hot paths. R=thestig@chromium.org Review URL: https://codereview.chromium.org/1719543002 .
Diffstat (limited to 'core/include')
-rw-r--r--core/include/fxcrt/fx_basic.h27
1 files changed, 9 insertions, 18 deletions
diff --git a/core/include/fxcrt/fx_basic.h b/core/include/fxcrt/fx_basic.h
index 018a91462e..9b1eaa5bf5 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: