From 6fb598b9dff93602134f1976443ae6d6ff015c4d Mon Sep 17 00:00:00 2001 From: tsepez Date: Tue, 5 Apr 2016 12:40:47 -0700 Subject: Make StringData a templated class. First step in making the same changes to CFX_WideString that we just made to CFX_ByteString. Review URL: https://codereview.chromium.org/1844073003 --- core/fxcrt/include/fx_string.h | 45 ++---------------------------------------- 1 file changed, 2 insertions(+), 43 deletions(-) (limited to 'core/fxcrt/include/fx_string.h') diff --git a/core/fxcrt/include/fx_string.h b/core/fxcrt/include/fx_string.h index 9373b058ee..e084f50cfd 100644 --- a/core/fxcrt/include/fx_string.h +++ b/core/fxcrt/include/fx_string.h @@ -10,6 +10,7 @@ #include // For intptr_t. #include +#include "core/fxcrt/cfx_string_data_template.h" #include "core/fxcrt/include/cfx_retain_ptr.h" #include "core/fxcrt/include/fx_memory.h" #include "core/fxcrt/include/fx_system.h" @@ -282,49 +283,7 @@ class CFX_ByteString { static CFX_ByteString FormatFloat(FX_FLOAT f, int precision = 0); protected: - class StringData { - public: - static StringData* Create(FX_STRSIZE nLen); - static StringData* Create(const StringData& other); - static StringData* Create(const FX_CHAR* pStr, FX_STRSIZE nLen); - - void Retain() { ++m_nRefs; } - void Release() { - if (--m_nRefs <= 0) - FX_Free(this); - } - - bool CanOperateInPlace(FX_STRSIZE nTotalLen) const { - return m_nRefs <= 1 && nTotalLen <= m_nAllocLength; - } - - void CopyContents(const StringData& other); - void CopyContents(const FX_CHAR* pStr, FX_STRSIZE nLen); - void CopyContentsAt(FX_STRSIZE offset, - const FX_CHAR* pStr, - FX_STRSIZE nLen); - - // To ensure ref counts do not overflow, consider the worst possible case: - // the entire address space contains nothing but pointers to this object. - // Since the count increments with each new pointer, the largest value is - // the number of pointers that can fit into the address space. The size of - // the address space itself is a good upper bound on it. - intptr_t m_nRefs; // Would prefer ssize_t, but no windows support. - - // |FX_STRSIZE| is currently typedef'd as |int|. - // TODO(palmer): It should be a |size_t|, or at least unsigned. - // These lengths do not include the terminating NUL, but the underlying - // buffer is sized to be capable of holding it. - FX_STRSIZE m_nDataLength; - FX_STRSIZE m_nAllocLength; - - // Not really 1, variable size. - FX_CHAR m_String[1]; - - private: - StringData(FX_STRSIZE dataLen, FX_STRSIZE allocLen); - ~StringData() = delete; - }; + using StringData = CFX_StringDataTemplate; void ReallocBeforeWrite(FX_STRSIZE nNewLen); void AllocBeforeWrite(FX_STRSIZE nNewLen); -- cgit v1.2.3