summaryrefslogtreecommitdiff
path: root/core/fxcrt/include
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-04-05 12:40:47 -0700
committerCommit bot <commit-bot@chromium.org>2016-04-05 12:40:47 -0700
commit6fb598b9dff93602134f1976443ae6d6ff015c4d (patch)
tree0863a7d3f53be87b7ec963fa4f16f7cd22e6ca4d /core/fxcrt/include
parentfc58ad18b7ab32e7b0bb3959b07dbe7538a7cebd (diff)
downloadpdfium-6fb598b9dff93602134f1976443ae6d6ff015c4d.tar.xz
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
Diffstat (limited to 'core/fxcrt/include')
-rw-r--r--core/fxcrt/include/fx_string.h45
1 files changed, 2 insertions, 43 deletions
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 <stdint.h> // For intptr_t.
#include <algorithm>
+#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<FX_CHAR>;
void ReallocBeforeWrite(FX_STRSIZE nNewLen);
void AllocBeforeWrite(FX_STRSIZE nNewLen);